Platform SDK: Active Directory, ADSI, and Directory Services

Modifying Attributes with the IDirectoryObject Interface

In addition to IADs::Put and IADs::PutEx, you may use the IDirectoryObject::SetObjectAttributes method. To use this method, you must create an ADS_ATTR_INFO structure and set attribute names and values within the structure. You are responsible for allocating and destroying this structure. You must also pass the number of attributes to be modified.

IDirectoryObject::SetObjectAttributes allows you to modify attributes with both single and multiple values. This function gives similar operational controls (clear, append, delete, and update) to those found in IADs::PutEx. The control constants are:

Note  Like IADs::Put and IADs::PutEx with IADs::SetInfo, the attribute changes are either committed or discarded in Active Directory on a transaction basis.

Example:

HRESULT hr; 
 
IDirectoryObject *pDirObject=NULL; 
DWORD dwReturn; 
ADSVALUE snValue; 
 
ADS_ATTR_INFO attrInfo[] = {{L"sn",ADS_ATTR_UPDATE,ADSTYPE_CASE_IGNORE_STRING,&snValue,1}};
 
DWORD dwAttrs = sizeof(attrInfo)/sizeof(ADS_ATTR_INFO); 
 
snValue.dwType=ADSTYPE_CASE_IGNORE_STRING; 
snValue.CaseIgnoreString = L"William"; 
 
hr = ADsGetObject(L"LDAP://CN=Bruce Johnson,OU=Sales,DC=Microsoft,DC=com", IID_IDirectoryObject, (void**) &pDirObject); 
 
if ( SUCCEEDED(hr) ) 
{ 
  hr=pDirObject->SetObjectAttributes(attrInfo, dwAttrs, &dwReturn);
} 
 
pDirObject->Release();