Directory Services |
The IADsContainer::CopyHere method creates a copy of the specified directory object in this container.
HRESULT CopyHere( BSTR bstrSourceObject, BSTR bstrNewName, IDispatch** ppNewObject );
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.
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.
[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();
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.