Directory Services |
The IADsPropertyValue2::PutObjectProperty method sets the property values of an ADSI object.
HRESULT PutObjectProperty( long lnADsType, VARIANT pvProp );
The method supports the standard HRESULT return values, including S_OK. For more information and other return values, see ADSI Error Codes.
The following code example shows how to use IADsPropertyValue2::PutObjectProperty to change a property value, descString, of the property entry in a property list.
Dim propList As IADsPropertyList Dim propEntry As IADsPropertyEntry Dim propVal As IADsPropertyValue2 Dim descString As String On Error GoTo Cleanup Set propList = GetObject("LDAP://dc01/DC=Fabrikam,DC=com") propList.GetInfo Set propEntry = propList.GetPropertyItem("description", ADSTYPE_CASE_IGNORE_STRING) descString = "This is Fabrikam.com" For Each v In propEntry.Values Set propVal = v propVal.PutObjectProperty ADSTYPE_CASE_IGNORE_STRING, descString Next propList.Setinfo Cleanup: If (Err.Number<>0) Then MsgBox("An error has occurred. " & Err.Number) End If Set propList = Nothing Set propEntry = Nothing Set propVal = Nothing
The following code example shows how to use IADsPropertyValue2::PutObjectProperty to change a property value, descString, of the property entry in a property list.
#include <activeds.h> #include <stdio.h> IADsPropertyList *pList; IADsPropertyEntry *pEntry; IADsPropertyValue2 *pVal2; IADs *pObj; VARIANT var, varProp, varItem; long valType = ADSTYPE_CASE_IGNORE_STRING; IEnumVARIANT *pEnum = NULL; LONG lstart, lend; VariantInit(&var); // Bind to the directory object. HRESULT hr = ADsGetObject(L"LDAP://dc01/DC=Fabrikam,DC=com", IID_IADsPropertyList, (void**)&pList); // Initialize the property cache. hr = pList->QueryInterface(IID_IADs,(void**)&pObj); pObj->GetInfo(); pObj->Release(); // Get a property entry. hr = pList->GetPropertyItem(CComBSTR("description"), valType, &var); hr = V_DISPATCH(&var)->QueryInterface(IID_IADsPropertyEntry, (void**)&pEntry); VariantClear(&var); // Get the property value object. hr = pEntry->get_Values(&var); SAFEARRAY *sa = V_ARRAY( &var ); long item = 0; hr = SafeArrayGetElement( sa, &item, &varItem ); hr = V_DISPATCH(&varItem)->QueryInterface(IID_IADsPropertyValue2, (void**)&pVal2); V_BSTR(&varProp) = "This is Fabrikam.com"; hr = pVal2->PutObjectProperty(&valType,&varProp); // Commit the change to the directory store. hr = pList->SetInfo(); Cleanup: if(pList) pList->Release(); if(pEntry) pEntry->Release(); if(pVal2) pVal2->Release(); if(pEnum) pEnum->Release(); VariantClear(&varItem); VariantClear(&varProp); VariantClear(&var);
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.
ADSI Error Codes, ADSTYPEENUM, IADsPropertyValue, IADsPropertyValue2