Sunday, July 25, 2010

User Management using ADSI

The listing demonstrates how to use Active Directory Service to manage the users on WinNT and Windows 2000.

IADsContainer interface lets you crawl through the active directory. To manage users, you need to get ADS object with pathWinNT://DomianName/MachineName. IADsWinNTSystemInfo interface provides this information. Once we have a container, we enumerate through the container and if the object supports IADsUser interface, we add it as the user in the ListView. IADsUser then lets you manage properties for individual users.

 Collapse

//Get the Information about system name and domain name


IADsWinNTSystemInfo *pNTsys;
HRESULT hr = CoCreateInstance(CLSID_WinNTSystemInfo,
  NULL,CLSCTX_INPROC_SERVER,
  IID_IADsWinNTSystemInfo,  (void**)&pNTsys);
pNTsys->AddRef();
BSTR bstrCompName;
pNTsys->get_ComputerName(&bstrCompName);
CString cscompName=bstrCompName;
SysFreeString(bstrCompName);
BSTR bstrDomainName;
pNTsys->get_DomainName(&bstrDomainName);
CString CSDomainName=bstrDomainName;
SysFreeString(bstrDomainName);
pNTsys->Release();

//Form ADSPath

ADSPath.Format("WinNT://%s/%s",CSDomainName,cscompName);

//Get the container object

hr=ADsGetObject(ADSPath.AllocSysString(),IID_IADsContainer,(void **)&pUsers);

Read more: Codeproject

Posted via email from .NET Info