Platform SDK: Active Directory, ADSI, and Directory Services |
The IADs::PutEx method is used to modify cached values of a specified property with a greater degree of control. For example, you can append a value to the existing ones of a multi-valued property, change all the values at once, remove the specified values from the set, or delete all the values at once.
HRESULT IADs::PutEx( LONG lnControlCode, BSTR bstrName, VARIANT vProp );
This method supports the standard return values, as well as the following:
For other return values, see ADSI Error Codes.
After calling IADs::PutEx, you must call IADs::SetInfo to commit the changes in the cache to the underlying directory store , if you wish to make the changes persistent.
The following Visual Basic code snippet shows how to use IADs::PutEx with the control code to modify values of a named property.
Dim x As IADs Set x = GetObject("LDAP://CN=Administrator,CN=Users,DC=Fabrikam,DC=com") '---------------------------------------------- ' Assume the otherHomePhoneNumber has the following values: ' 111-1111, 222-2222 '---------------------------------------------- ' Adding a value x.PutEx ADS_PROPERTY_APPEND, "OtherhomePhone", Array("333-3333") x.SetInfo 'Now the values are 111-1111,222-222,333-3333 ' deleting two values x.PutEx ADS_PROPERTY_DELETE, "OtherHomePhone", Array("111-1111", "222-2222") x.SetInfo 'Now the values are 333-3333 ' changing the remaining value x.PutEx ADS_PROPERTY_UPDATE, "OtherHomePhone", Array("888-8888", "999-9999") x.SetInfo 'Now the values are 888-8888,999-9999 'Deleting the value. x.PutEx ADS_PROPERTY_CLEAR, "OtherHomePhone", vbNullString x.SetInfo 'Now the property has no value
The following C++ code snippet uses IADs::PutEx to set some user attributes. For brevity, error checking is omitted.
HRESULT hr; IADs *pADs=NULL; LPWSTR pszADsPath = L"LDAP://CN=Administrator, CN=Users, DC=Fabrikam, DC=com"; CoInitialize(NULL); hr = ADsGetObject(pszADsPath, IID_IADs, (void**) &pADs ); VARIANT var; VariantInit(&var); LPWSTR pszPhones[] = { L"111-1111", L"222-2222" }; DWORD dwNumber = sizeof( pszPhones ) /sizeof(LPWSTR); hr = ADsBuildVarArrayStr( pszPhones, dwNumber, &var ); hr = pADs->Put( L"OtherHomePhone", var ); VariantClear(&var); hr = pADs->SetInfo(); // now the phone list is (111-1111, 222-2222) // Append another number to the list. LPWSTR pszAddPhones[]={L"333-3333"}; hr = ADsBuildVarArrayStr( pszAddPhones, 1, &var); hr = pADs->PutEx( ADS_PROPERTY_APPEND, L"OtherHomePhone", var ); hr = pADs->SetInfo(); //the list becomes // (111-1111, 222-2222, 333-3333) VariantClear(&var); hr = ADsBuildVarArrayStr( pszPhones, dwNumber, &var); hr = pADs->PutEx( ADS_PROPERTY_DELETE, L"OtherHomePhone", var); hr = pADs->SetInfo(); // the list becomes (333-3333) pszPhones[0] = L"888-8888"; pszPhones[1] = L"999-9999"; hr = ADsBuildVarArrayStr( pszPhones, dwNumber, &var); hr = pADs->PutEx( ADS_PROPERTY_UPDATE, L"OtherHomePhone", var); hr = pADs->SetInfo(); // the list becomes (888-8888, 999-9999) VariantClear(&var); V_VT(&var)=VT_NULL; hr = pADs->PutEx( ADS_PROPERTY_CLEAR, L"OtherHomePhone", var); hr = pADs->SetInfo(); // the list is now empty hr = 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.