First, you will have to add a reference to the 'Active Directory DS' COM object.
Second, add the statement: using ActiveDS;
Here is a GroupNames() function to demo the process:
using ActiveDS;
public static string[] GroupNames(string userName)
{
List
if (String.IsNullOrEmpty(userName) == true)
{
return null;
}
userName = userName.Trim().Replace('\\', '/');
DirectoryEntry de = new DirectoryEntry(String.Format("WinNT://{0},user", userName));
IADsMembers groupsForUser = (IADsMembers) de.Invoke("Groups",null);
foreach (object group in groupsForUser)
{
DirectoryEntry deGroup = new DirectoryEntry(group);
result.Add(deGroup.Name);
}
if (result.Count == 0)
{
return null;
}
return result.ToArray();
}