Click here to Skip to main content
13,458,661 members
Click here to Skip to main content
Add your own
alternative version


24 bookmarked
Posted 23 Mar 2001

User Management using ADSI

, 23 Mar 2001
Rate this:
Please Sign up or sign in to vote.
This article demonstrates user management using Active Directory Services

Sample Image - adsiuserdmo.gif


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, 
   IID_IADsWinNTSystemInfo,  (void**)&pNTsys);
BSTR bstrCompName;
CString cscompName=bstrCompName;
BSTR bstrDomainName;
CString CSDomainName=bstrDomainName;

//Form ADSPath

//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;
    _variant_t vChild;
    hr=ADsEnumerateNext (pEnum,1,&vChild,NULL);
    //Iterate as long as you get S_OK 
    hr=vChild.pdispVal->QueryInterface (IID_IADsUser,(void **)&pChild);
        //This object is user


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
No Biography provided

You may also be interested in...


Comments and Discussions

QuestionWhich Win32 API is used ? Pin
Abhinav agrawal2-Feb-06 1:21
memberAbhinav agrawal2-Feb-06 1:21 
GeneralPassword Pin
mendezhe5-Aug-05 9:46
membermendezhe5-Aug-05 9:46 
GeneralRe: Password Pin
Le Thanh Cong13-Apr-06 23:38
memberLe Thanh Cong13-Apr-06 23:38 
GeneralI still have unresolved externals Pin
zim32726-Aug-04 5:07
memberzim32726-Aug-04 5:07 
GeneralRe: I still have unresolved externals Pin
zim32726-Aug-04 9:47
memberzim32726-Aug-04 9:47 
GeneralRe: I still have unresolved externals Pin
kelprinc29-Jan-06 22:57
memberkelprinc29-Jan-06 22:57 
Generalcreating a new Group policy thru Code Pin
chettu20-Jun-04 20:46
memberchettu20-Jun-04 20:46 
GeneralRe: creating a new Group policy thru Code Pin
manjarijain14-May-07 4:43
membermanjarijain14-May-07 4:43 
I need to do exactly same thing. Were you able to get solution to this issue. Please let me know if you were able to create a group policy through code.

GeneralRe: creating a new Group policy thru Code Pin
tankSanju28-May-07 21:33
membertankSanju28-May-07 21:33 
GeneralGetting Unresolved External yet have VS.Net 2003 Pin
sarahl26-Apr-04 4:32
membersarahl26-Apr-04 4:32 
GeneralADsGetObject showing memory leak Pin
Anonymous25-Feb-04 19:15
sussAnonymous25-Feb-04 19:15 
Questionget_EmailAddress? Pin
DuneAgent114-Aug-03 1:22
memberDuneAgent114-Aug-03 1:22 
AnswerRe: get_EmailAddress? Pin
iknowindigo27-Sep-06 11:58
memberiknowindigo27-Sep-06 11:58 
GeneralRe: get_EmailAddress? Pin
DuneAgent27-Sep-06 12:33
memberDuneAgent27-Sep-06 12:33 
GeneralRe: get_EmailAddress? Pin
iknowindigo28-Sep-06 9:39
memberiknowindigo28-Sep-06 9:39 
GeneralRe: get_EmailAddress? Pin
DuneAgent29-Sep-06 15:18
memberDuneAgent29-Sep-06 15:18 
GeneralUndeclared Identifier in IADsWinNTSystemInfo Pin
a_sangee19-Mar-02 22:47
membera_sangee19-Mar-02 22:47 
GeneralRe: Undeclared Identifier in IADsWinNTSystemInfo Pin
sanbad20-Feb-04 1:52
susssanbad20-Feb-04 1:52 
GeneralRe: Undeclared Identifier in IADsWinNTSystemInfo Pin
iknowindigo27-Sep-06 12:00
memberiknowindigo27-Sep-06 12:00 
GeneralRe: Undeclared Identifier in IADsWinNTSystemInfo Pin
krzysio_3133718-Dec-06 10:37
memberkrzysio_3133718-Dec-06 10:37 
GeneralIADS.h Pin
Amjad W. Hawash24-Nov-01 23:03
memberAmjad W. Hawash24-Nov-01 23:03 
GeneralRe: IADS.h Pin
Digital Spirits14-Nov-02 23:53
memberDigital Spirits14-Nov-02 23:53 
QuestionNice Example, but? Pin
Ollie18-Jun-01 5:33
memberOllie18-Jun-01 5:33 
AnswerRe: Nice Example, but? Pin
Dieter Kunz24-Sep-01 22:24
memberDieter Kunz24-Sep-01 22:24 
GeneralRe: Nice Example, but? Pin
Dieter Kunz24-Sep-01 22:26
memberDieter Kunz24-Sep-01 22:26 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

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