querying for local groups


I'd like to retrieve all local groups on my machine (Vista in a W2k3 domain).

If I run:

using (DirectoryEntry de = new DirectoryEntry("WinNT://" + Environment.MachineName + ",group", null, null, AuthenticationTypes.Secure))


it throws an "unknown error" 0x80005000 which apparently means "invalid path"

However querying for computers (change ,group to ,computer) doesn't raise an error, but it seems to be ignored (it returns all objects? I haven't fully examined the result). ,user also raises the error.

So my question is, am I on the right path? is there a way to apply a filter so I don't retrieve everything? If so, where can I find the correct syntax?

asked on Stack Overflow Sep 3, 2009 by Will I Am • edited Sep 3, 2009 by Will I Am

1 Answer


I believe you need to get the machine - groups are a child of that.


DirectoryEntry machine = new DirectoryEntry("WinNT://" + Environment.MachineName + ",Computer");
foreach (DirectoryEntry child in machine.Children)
    if (child.SchemaClassName == "Group")

Feel free to spice it up with some LINQ, but this should give you the base idea.

answered on Stack Overflow Sep 3, 2009 by Philip Rieck

User contributions licensed under CC BY-SA 3.0