If you want to have the list of an specific windows group in C# you can get this list by these lines of code below. Notice that you have to add a reference to System.DirectoryServices .
DirectoryEntry localMachine = new DirectoryEntry("WinNT://" + Environment.MachineName);
DirectoryEntry admGroup = localMachine.Children.Find("administrators","group");
object members = admGroup.Invoke("members", null);
foreach (object groupMember in (IEnumerable)members)
{
DirectoryEntry member = new DirectoryEntry(groupMember);
lstUsers.Items.Add(member.Name);
}
you can download the source code here:
http://www.tabatabaei.info/csharpsamples/WindowsGroupMember.rar
Monday, September 10, 2007
How to get list of windows user in C#
Subscribe to:
Post Comments (Atom)

4 comments:
Dude!
That code was just the thing I was looking for - and simple too.
Thanks a million.
Paul.
Hi,
thanks verymuch for code to get the windows group user list,
How can I know the the particular user FirstName and LastName.
please let me know.
Thanks in advance,
Udaya Bhaskar.
thanks
This code is great!
One question, is there something that can be added to list out the nested group members?
Post a Comment