Platform SDK: Active Directory, ADSI, and Directory Services

IADsPropertyValue2::PutObjectProperty

The IADsPropertyValue2::PutObjectProperty method sets the property values of an ADSI object.

HRESULT IADsPropertyValue2::PutObjectProperty(
  long lnADsType,
  VARIANT pvProp
);

Parameters

lnADsType
[in] An integer to indicate the ADsType to be set to the data referred to by pvProp. ADSI-defined data types can be found in the ADSTYPE enumeration.
pvProp
[in] Property values of the VARIANT type, including VT_BSTR for strings, VT_UI1 for bytes, VT_DATE for time, and VT_DISPATCH for objects representing the property values.

Return Values

The method supports the standard HRESULT return values, including S_OK. For other return values, see ADSI Error Codes.

Example Code [Visual Basic]

The following Visual basic code snippet 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 propEnty As IADsPropertyEntry
Dim propVal As IADsPropertyValue2
Dim descString as String
 
Set propList = GetObject("LDAP://dc01/DC=Microsoft,DC=com")
propList.GetInfo
 
Set propEntry = propList.GetPropertyItem("description", ADSTYPE_CASE_IGNORE_STRING)
 
descString = "This is Microsoft.com"
For Each v In propEntry.Values
    Set propVal = v
    propVal.PutObjectProperty ADSTYPE_CASE_IGNORE_STRING, descString
Next
propList.Setinfo

Example Code [C++]

The following C++ code snippet 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 directory object
HRESULT hr = ADsGetObject(L"LDAP://dc01/DC=Microsoft,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(L"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 Microsoft.com";
hr = pVal2->PutObjectProperty(&valType,&varProp);
 
// commit the change to the directory store.
hr = pList->SetInfo();
VariantClear(&var);

Requirements

  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.

See Also

ADSI Error Codes, ADSTYPEENUM, IADsPropertyValue, IADsPropertyValue2