Directory Services |
The IADs::Put method enables a client to set new values to a specified property in the ADSI property cache.
HRESULT Put( BSTR bstrName, VARIANT vProp );
For more information, and other return values, see ADSI Error Codes.
Return Code | Description |
---|---|
S_OK | The method succeeded. |
E_ADS_CANT_CONVERT_DATATYPE | The ADSI data type cannot be converted to or from the native data type of the underlying directory. |
The assignment of the new property values, performed by Put takes place in the property cache only. To propagate the changes to the directory store, call IADs::SetInfo on the object after calling Put.
To manipulate the property values beyond a simple assignment, use Put to append or remove a value from an existing array of attribute values.
The following code example demonstrates how to use the IADs::Put method with Visual Basic.
Dim x As IADs On Error GoTo Cleanup Set x = GetObject("LDAP://CN=JeffSmith,CN=Users,DC=Fabrikam, DC=Com") x.Put "givenName", "Jeff" x.Put "sn", "Smith" x.SetInfo ' Commit to the directory. Cleanup: If(Err.Number<>0) Then MsgBox("An error has occurred. " & Err.Number) End If Set x = Nothing
The following code example demonstrates how to use the IADs::Put method with C++.
HRESULT hr; IADs *pADs = NULL; LPWSTR pszADsPath = L"LDAP://CN=JeffSmith,CN=Users,DC=Fabrikam,DC=com"; CoInitialize(NULL); ////////////////////////////////// // Modifying attributes using IADs ////////////////////////////////// hr = ADsGetObject(pszADsPath, IID_IADs, (void**) &pADs); if(SUCCEEDED(hr)) { VARIANT var; VariantInit(&var); // Set the first name. V_BSTR(&var) = SysAllocString(L"Jeff"); V_VT(&var) = VT_BSTR; hr = pADs->Put(CComBSTR("givenName"), var); // Set the last name. VariantClear(&var); V_BSTR(&var) = SysAllocString(L"Smith"); V_VT(&var) = VT_BSTR; hr = pADs->Put(CComBSTR("givenName"), var); VariantClear(&var); // Other Telephones. LPWSTR pszPhones[] = { L"425-707-9790", L"425-707-9791" }; DWORD dwNumber = sizeof(pszPhones)/sizeof(LPWSTR); hr = ADsBuildVarArrayStr(pszPhones, dwNumber, &var); hr = pADs->Put(CComBSTR("otherTelephone"), var); VariantClear(&var); // Commit the change to the directory. hr = pADs->SetInfo(); pADs->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.