This topic has not yet been rated - Rate this topic

IADsContainer::CopyHere method

Applies to: desktop apps only

The IADsContainer::CopyHere method creates a copy of the specified directory object in this container.

Syntax

HRESULT CopyHere(
  [in]   BSTR bstrSourceObject,
  [in]   BSTR bstrNewName,
  [out]  IDispatch **ppNewObject
);

Parameters

bstrSourceObject [in]

The ADsPath of the object to copy.

bstrNewName [in]

Optional name of the new object within the container. If a new name is not specified for the object, set to NULL; the new object will have the same name as the source object.

ppNewObject [out]

Indirect pointer to the IADs interface on the copied object.

Return value

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

Remarks

The destination container must be in the same directory service as the source container. An object cannot be copied across a directory service implementation.

For the providers supplied with ADSI, only the NDS provider supports an implementation of this method. Other providers simply return the E_NOTIMPL error message.

Examples

The following code example copies a user object, "JeffSmith", to a new user object, "DeniseSmith", within the same organization unit. This example shows a short cut to create a new user.

Dim obj As IADsContainer
Dim newusr As IADsUser

On Error GoTo Cleanup
Set obj = GetObject("NDS://myTree/O=Fabrikam/OU=Sales")
Set newusr = obj.CopyHere("NDS://myTree/O=Fabrikam/OU=Sales/CN=JeffSmith", "JaneSmith")
newuser.EmployeeID = 151
newuser.FirstName = "Denise"
newuser.setInfo

Cleanup:
    If(Err.Number<>0) Then
        MsgBox("An error has occurred. " & Err.Number)
    End If
    Set obj = Nothing
    Set newusr = Nothing

The following code example copies a user object, "JeffSmith", to a new user object, "DeniseSmith", within the same organization unit. This example shows a short cut to create a new user.


IADsContainer *pCont = NULL;
IADsUser *pUser = NULL;
CComBSTR sbstr;
HRESULT hr = S_OK;
 
CoInitialize(NULL);

VariantInit(&var);
// Bind to an organization object.
hr = ADsGetObject(L"NDS://myTree/O=Fabrikam/OU=Sales",
                  IID_IADsContainer,
                  (void**)&pCont);

if(FAILED(hr)){goto Cleanup;}
 
// Create Denise Smith from Jeff Smith.
hr = pCont->CopyHere(CComBSTR("NDS://myTree/O=Fabrikam/OU=Sales/CN=JeffSmith"),
                     CComBSTR("DeniseSmith"),
                     (IADs**)&pUser);

if(FAILED(hr)){goto Cleanup;}

sbstr = "151";
pUser->put_EmployeeID(sbstr);
 
sbstr = "Jane";
pUser->put_FirstName(sbstr);
 
// Commit changes to the directory store.
pUser->SetInfo();

Cleanup:
    if(pCont)
        pCont->Release();
  
    if(pUser)
        pUser->Release();
 
CoUninitialize();

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Iads.h

DLL

Activeds.dll

IID

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

See also

IADsContainer
IADsContainer::MoveHere
IADs

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ