Click here to Skip to main content
Click here to Skip to main content

User Management using ADSI

By , 23 Mar 2001
 

Sample Image - adsiuserdmo.gif

Introduction

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 path WinNT://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.

//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);

//Now Enumerate through the container
IEnumVARIANTPtr pEnum; 
ADsBuildEnumerator (pUsers,&pEnum);
int cnt=0;
while(1)
{
    _variant_t vChild;
    hr=ADsEnumerateNext (pEnum,1,&vChild,NULL);
    //Iterate as long as you get S_OK 
    if(hr!=S_OK)
        break;
    hr=vChild.pdispVal->QueryInterface (IID_IADsUser,(void **)&pChild);
    if(hr!=S_OK)
        continue;
    else
        //This object is user
}

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here

About the Author

Vineet Nandurkar
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
QuestionWhich Win32 API is used ?memberAbhinav agrawal2 Feb '06 - 1:21 
GeneralPasswordmembermendezhe5 Aug '05 - 9:46 
GeneralRe: PasswordmemberLe Thanh Cong13 Apr '06 - 23:38 
GeneralI still have unresolved externalsmemberzim32726 Aug '04 - 5:07 
GeneralRe: I still have unresolved externalsmemberzim32726 Aug '04 - 9:47 
GeneralRe: I still have unresolved externalsmemberkelprinc29 Jan '06 - 22:57 
Generalcreating a new Group policy thru Codememberchettu20 Jun '04 - 20:46 
GeneralRe: creating a new Group policy thru Codemembermanjarijain14 May '07 - 4:43 
GeneralRe: creating a new Group policy thru CodemembertankSanju28 May '07 - 21:33 
GeneralGetting Unresolved External yet have VS.Net 2003membersarahl26 Apr '04 - 4:32 
GeneralADsGetObject showing memory leaksussAnonymous25 Feb '04 - 19:15 
Questionget_EmailAddress?memberDuneAgent114 Aug '03 - 1:22 
AnswerRe: get_EmailAddress?memberiknowindigo27 Sep '06 - 11:58 
GeneralRe: get_EmailAddress?memberDuneAgent27 Sep '06 - 12:33 
GeneralRe: get_EmailAddress?memberiknowindigo28 Sep '06 - 9:39 
GeneralRe: get_EmailAddress?memberDuneAgent29 Sep '06 - 15:18 
GeneralUndeclared Identifier in IADsWinNTSystemInfomembera_sangee19 Mar '02 - 22:47 
GeneralRe: Undeclared Identifier in IADsWinNTSystemInfosusssanbad20 Feb '04 - 1:52 
GeneralRe: Undeclared Identifier in IADsWinNTSystemInfomemberiknowindigo27 Sep '06 - 12:00 
GeneralRe: Undeclared Identifier in IADsWinNTSystemInfomemberkrzysio_3133718 Dec '06 - 10:37 
GeneralIADS.hmemberAmjad W. Hawash24 Nov '01 - 23:03 
GeneralRe: IADS.hmemberDigital Spirits14 Nov '02 - 23:53 
QuestionNice Example, but?memberOllie18 Jun '01 - 5:33 
AnswerRe: Nice Example, but?memberDieter Kunz24 Sep '01 - 22:24 
GeneralRe: Nice Example, but?memberDieter Kunz24 Sep '01 - 22:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web03 | 2.6.130516.1 | Last Updated 24 Mar 2001
Article Copyright 2001 by Vineet Nandurkar
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid