I need to find out if the user that is logged in (in active directory) is a
member of a certain group?
1) You need to add references to the System.DirectoryServices
namespace and the COM Active Ds Type Library to your project.
2) You can find out what the current user is by using this code:
// get a IADsADSystemInfo object and show it
ActiveDs.IADsADSystemInfo oSysInfo = new ActiveDs.ADSystemInfoClass();
string sCurrentUser = oSysInfo.UserName;
3) Now you can either bind to that user and look at the group he's a
member of, or you can do the reverse - bind to the group and see if
the user is a member of that group.
Given the user, you bind to the user object:
DirectoryEntry deUser = new DirectoryEntry("LDAP://" + sCurrentUser);
// enumerate his groups
foreach(object oGroup in deUser.Properties["memberOf"])
{
string sGroupName = oGroup.ToString();
if(sGroupName == "<your group name>")
{
// do something with that information
}
}
HTH
Marc
================================================================
Marc Scheuner May The Source Be With You!
Berne, Switzerland m.scheuner -at- inova.ch