Directory Services

IADsContainer::CopyHere

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

HRESULT CopyHere( 
  BSTR bstrSourceObject,
  BSTR bstrNewName,
  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 Values

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.

Example Code [Visual Basic]

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

Example Code [C++]

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.

[C++]
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

Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Iads.h.

See Also

IADsContainer, IADsContainer::MoveHere, IADs