Directory Services |
The IADsContainer::Create method sets up a request to create a directory object of the specified schema class and a given name in the container. The object is not made persistent until IADs::SetInfo is called on the new object. This allows for setting mandatory properties on the new object.
HRESULT Create( BSTR bstrClass, BSTR bstrRelativeName, IDispatch** ppNewObject );
The following code example shows how to create a user object using IADsContainer::Create with IADs::SetInfo.
Dim cont As IADsContainer Dim usr As IADsUser On Error GoTo Cleanup Set cont = GetObject("LDAP://OU=Sales,DC=Fabrikam,DC=com") Set usr = cont.Create("user", "CN=jeffsmith") usr.Put "samAccountName", "jeffsmith" usr.SetInfo Cleanup: If (Err.Number<>0) Then MsgBox("An error has occurred. " & Err.Number) End If Set cont = Nothing Set usr = Nothing
The following code example shows how to create a user object.
HRESULT hr = S_OK; IADsContainer *pCont = NULL; IADs *pADs=NULL; IDispatch *pDisp=NULL; CoInitialize(NULL); hr = ADsGetObject( L"WinNT://myMachine", IID_IADsContainer, (void**) &pCont ); if (!SUCCEEDED(hr) ) {goto Cleanup;} hr = pCont->Create(CComBSTR("user"), CComBSTR("cn=JeffSmith"), &pDisp ); pCont->Release(); if( !SUCCEEDED(hr) ) { goto Cleanup; } hr = pDisp->QueryInterface( IID_IADs, (void**) &pADs ); pDisp->Release(); if ( !SUCCEEDED(hr) ) { goto Cleanup;} pADs->SetInfo(); // Commit Cleanup: if(pADs) pADs->Release(); if(pCont) pCont->Release(); if(pDisp) pDisp->Release(); return hr;
Client: Included in Windows XP and
Windows 2000 Professional.
Server: Included in Windows Server 2003 and
Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension
on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Iads.h.
IADsContainer, IADsContainer::Delete, IDispatch