Export (0) Print
Expand All

IADsContainer::Create method

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.

Syntax


HRESULT Create(
  [in]   BSTR bstrClass,
  [in]   BSTR bstrRelativeName,
  [out]  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 value

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

Examples

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;
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);
if(!SUCCEEDED(hr))
{
    goto Cleanup; 
}
 
hr = pDisp->QueryInterface(IID_IADs, (void**) &pADs);
if(!SUCCEEDED(hr))
{
    goto Cleanup;
}
 
pADs->SetInfo(); // Commit

Cleanup:
if(pADs)
{
    pADs->Release();
}

if(pCont)
{
    pCont->Release();
}

if(pDisp)
{
    pDisp->Release();
}

return hr;

Requirements

Minimum supported client

Windows Vista [desktop apps only]

Minimum supported server

Windows Server 2003 [desktop apps only]

Header

Iads.h

DLL

Activeds.dll

IID

IID_IADsContainer is defined as 001677D0-FD16-11CE-ABC4-02608C9E7553

See also

IADsContainer
IADsContainer::Delete
IDispatch

 

 

Show:
© 2014 Microsoft