"Claus Konrad" <so*@meal.it> wrote in message
news:Ob*************@TK2MSFTNGP09.phx.gbl...
What's the best way to retrieve information on who is member of e.g.
SecurityGroup "ABC.SecGrp1"?
There are several ways to do this. I'd suggest posting your message on
microsoft.public.adsi.general where you can take anything Joe Kaplan says as
pretty much definitive... :-)
In the meantime, here's a function which accepts the group as a parameter
and returns a Hashtable of the members of that group:
using System;
using System.Collections;
using System.DirectoryServices;
public static Hashtable GetUsersInGroup(string pstrGroup)
{
DirectoryEntry objADEntry = null;
DirectoryEntry objGroup = null;
object objMembers = null;
Hashtable htblUsers = new Hashtable();
try
{
objADEntry = new DirectoryEntry("WinNT://" + mstrDomain + ",
domain");
objGroup = objADEntry.Children.Find(pstrGroup, "group");
objMembers = objGroup.Invoke("Members");
foreach (object objMember in (IEnumerable)objMembers)
{
DirectoryEntry objUser = new DirectoryEntry(objMember);
htblUsers.Add(objUser.Name, GetObjectProperty(objUser.Name,
"FullName"));
}
return htblUsers;
}
catch (Exception)
{
throw;
}
}