-1

I'm trying to enumerate all existing groups on my local machine.

That's what I tried using wmi :

string _class = "Win32_GroupUser";
string namespace = "\\\\.\\ROOT\\cimv2";

ManagementClass _class = new ManagementClass(namespace + ":" + class );    

foreach (ManagementObject _object in _class.GetInstances())
{
    richTextBox1.AppendText((_object["GroupComponent"].ToString()));
}

Output example :

\DESKTOP-2MSGC9J\root\cimv2:Win32_Group.Domain="DESKTOP-2MSGC9J",Name="Utilisateurs du journal de performances"

In this output only the group name Name="Utilisateurs du journal de performances" is important to me.

Is a way to do a wmi query that only return that element in this _object ?

Another foreach with _object maybe.

ekad
  • 14,436
  • 26
  • 44
  • 46
ShEp
  • 87
  • 1
  • 5

1 Answers1

0

I find a dirty way using substring after getting my object from wmi.

foreach (ManagementObject _object in _class.GetInstances())
{
    string groups = _object["GroupComponent"].ToString();
    int i = groups.LastIndexOf('=') + 1;
    string groupsName = groups.Substring(i);
    richTextBox1.AppendText(groupsName + "\r\n\r\n");
}
ShEp
  • 87
  • 1
  • 5