"mc" <mc@community.nospamwrote in message
news:46********@mail.hmgcc.gov.uk...
>I would like to check if a user is currently a member of a Local Group on
the server. I am able to do the test for the current user and all is ok,
however I would like to be able to take a list of users from a table in the
database and check if the user is in the specified group. is it possible to
take a username (as a string) and create an instance of IPricipal for that
user? or achive by any other method?
The following code returned true if UserName is a member of a Power Users
group.
DirectoryEntry entryRoot = new DirectoryEntry("WinNT://" +
Environment.MachineName + ",computer",
Environment.MachineName +"\\" + SuperUserName, SuperUserPassword,
System.DirectoryServices.AuthenticationTypes.Reado nlyServer);
DirectoryEntry userEntry = entryRoot.Children.Find(UserName, "user");
DirectoryEntry objGroup = entryRoot.Children.Find("Power Users", "group");
bool isMember = (bool)objGroup.Invoke("IsMember", new object[] {
userEntry.Path.ToString() });
SuperUserName is a local user