Platform SDK: Active Directory, ADSI, and Directory Services |
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 );
This method supports the standard return values, including S_OK for a successful operation. For error code information, see ADSI Error Codes.
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.
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
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();
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.