1 out of 3 rated this helpful - Rate this topic

IADs::Put method

Applies to: desktop apps only

The IADs::Put method sets the values of an attribute in the ADSI attribute cache.

Syntax

HRESULT Put(
  [in]  BSTR bstrName,
  [in]  VARIANT vProp
);

Parameters

bstrName [in]

Contains a BSTR that specifies the property name.

vProp [in]

Contains a VARIANT that specifies the new values of the property.

Return value

This method supports the standard return values, as well as the following.

For more information, and other return values, see ADSI Error Codes.

Return codeDescription
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.

 

Remarks

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.

Examples

The following code example shows how to use the IADs::Put method.

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 shows how to use the IADs::Put method.


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("sn"), 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();

Requirements

Minimum supported client

Windows 2000 Professional

Minimum supported server

Windows 2000 Server

Header

Iads.h

DLL

Activeds.dll

IID

IID_IADs is defined as FD8256D0-FD15-11CE-ABC4-02608C9E7553

See also

IADs
IADs::Get
IADs::GetEx
IADs::PutEx
Property Cache

 

 

Send comments about this topic to Microsoft

Build date: 2/3/2012

Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ