Platform SDK: Active Directory, ADSI, and Directory Services

IADsContainer::Create

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

Parameters

bstrClass
[in] Name of the schema class object to be created. The name is that returned from the IADs::get_Schema property method.
bstrRelativeName
[in] Relative name of the object as it is known in the underlying directory and identical to the one retrieved through the IADs::get_Name property method.
ppNewObject
[out] Indirect pointer to the IDispatch interface on the newly created object.

Return Values

This method supports the standard return values, including S_OK for a successful operation. For error code information, see ADSI Error Codes.

Example Code[Visual Basic]

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

Example Code[C++]

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

Requirements

  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.

See Also

IADsContainer, IADsContainer::Delete, IDispatch