Platform SDK: Active Directory, ADSI, and Directory Services

IADsContainer::CopyHere

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

HRESULT IADsContainer::CopyHere(
  BSTR bstrSourceObject,  
  BSTR bstrNewName,       
  IADs ** ppNewObject     
);

Parameters

bstrSourceObject
[in] The ADsPath of the object to be copied.
bstrNewName
[in] Optional name of the new object within the container.
ppNewObject
[out] Indirect pointer to the IADs interface on the copied 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.

Remarks

The destination container must be in the same directory service as the source container. Copying objects across directory service implementations is not permitted.

Of the Microsoft-supplied providers, only the NDS provider supports a non trivial implementation of this method. Other providers simply return the E_NOTIMPL error message.

Example Code [Visual Basic]

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

Dim obj as IADsContainer
Dim newusr as IADsUser
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 = "Jane"
newuser.setInfo

Example Code [C++]

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

IADsContainer *pCont;
IADsUser *pUser;
VARIANT var;
HRESULT hr;
 
CoInitialize(NULL);
 
// bind to an organization object
hr = ADsGetObject(L"NDS://myTree/O=Fabrikam/OU=Sales",
                  IID_IADsContainer,
                  (void**)&pCont);
 
// create Jane Smith from Jeff Smith.
pCont->CopyHere(L"NDS://myTree/O=Fabrikam/OU=Sales/CN=JeffSmith",
                L"JaneSmith",
                (IADs**)&pUser);
VariantInit(&var);
V_BSTR(&var) = SysAllocString(L"151");
V_VT(&var) = VT_BSTR;
pUser->put_EmployeeID(var);
 
VariantClear(&var);
V_BSTR(&var)=SysAllocString(L"Jane");
pUser->put_FirstName(var);
 
// commit changes to the directory store.
pUser->SetInfo();
 
CoUninitialize();

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::MoveHere, IADs