Platform SDK: Active Directory, ADSI, and Directory Services |
The IADs::Put method lets a client set new values to a specified property in the property cache.
HRESULT IADs::Put( BSTR bstrName, VARIANT vProp );
This method supports the standard return values, as well as the following:
For other return values, see ADSI Error Codes.
The assignment of the new property values, performed by IADs::Put, takes place in the property cache only. To propagate the changes to the directory store, you must call IADs::SetInfo on the object after calling IADs::Put. To manipulate the property values beyond the simple assignment, use IADs::PutEx, which allows you to append a value to or remove one from an existing array of attribute values.
The following Visual Basic code snippet shows how to use the IADs::Put method.
Dim x As IADs Set x = GetObject("LDAP://CN=JSmith,CN=Users,DC=Fabrikam, DC=Com") x.Put "givenName", "Jeff" x.Put "sn", "Smith" x.SetInfo 'commit to the directory
The following C++ code snippet uses IADs::Put to set some user attributes.
HRESULT hr; IADs *pADs=NULL; LPWSTR pszADsPath = L"LDAP://CN=JSmith, CN=Users, DC=Fabrikam, DC=com"; CoInitialize(NULL); ////////////////////////////////// // Modifying attributes using IADs ////////////////////////////////// hr = ADsGetObject(pszADsPath, IID_IADs, (void**) &pADs ); if (!SUCCEEDED(hr) ) { return hr; } VARIANT var; VariantInit(&var); // Setting the first name V_BSTR(&var) = SysAllocString(L"Jeff"); V_VT(&var) = VT_BSTR; hr = pADs->Put( L"givenName", var ); // Setting the last name VariantClear(&var); V_BSTR(&var) = SysAllocString(L"Smith"); V_VT(&var) = VT_BSTR; hr = pADs->Put( L"givenName", var ); VariantClear(&var); // Other Telephones LPWSTR pszPhones[] = { L"425 844 1234", L"425 924 4321" }; DWORD dwNumber = sizeof( pszPhones ) /sizeof(LPWSTR); hr = ADsBuildVarArrayStr( pszPhones, dwNumber, &var ); hr = pADs->Put( L"otherTelephone", var ); VariantClear(&var); // Commit the change to the directory hr = pADs->SetInfo(); pADs->Release(); if (!SUCCEEDED(hr) ) { return hr; }
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.