| Platform SDK: Active Directory, ADSI, and 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 IADsContainer::Create( BSTR bstrClass, BSTR bstrRelativeName, IDispatch ** ppNewObject );
This method supports the standard return values, including S_OK for a successful operation. For error code information, see ADSI Error Codes.
The following Visual Basic code snippet illustrates how to create a user object using IADsContainer::Create with IADs::SetInfo.
Dim cont as IADsContainer
Dim usr as IADsUser
Set cont = GetObject("LDAP://OU=Sales,DC=Fabrikam,DC=com")
Set usr = cont.Create("user", "CN=jsmith")
usr.Put "samAccountName", "jsmith"
usr.SetInfo
The following C++ code snippet shows how to create a user object.
HRESULT hr;
IADsContainer *pCont = NULL;
CoInitialize(NULL);
hr = ADsGetObject( L"WinNT://myMachine",
IID_IADsContainer,
(void**) &pCont );
if (!SUCCEEDED(hr) ) {return hr;}
IADs *pADs=NULL;
IDispatch *pDisp=NULL;
hr = pCont->Create(L"user", L"JSmith", &pDisp );
pCont->Release();
if( !SUCCEEDED(hr) ) { return hr; }
hr = pDisp->QueryInterface( IID_IADs, (void**) &pADs );
pDisp->Release();
if ( !SUCCEEDED(hr) ) { return 0;}
pADs->SetInfo(); // Commit
pADs->Release(); // Release
Windows NT/2000: Requires Windows 2000 (or Windows NT 4.0 with DSClient).
Windows 95/98: Requires Windows 95 or later (with DSClient).
Header: Declared in Iads.h.