Platform SDK: Active Directory, ADSI, and Directory Services |
The IDirectoryObject::GetObjectAttributes method gets one or more specified attributes of the directory service object, as defined in the ADS_ATTR_INFO structure.
HRESULT GetObjectAttributes( LPWSTR * pAttributeNames, DWORD dwNumberAttributes, PADS_ATTR_INFO * ppAttributeEntries, DWORD * pdwNumAttributesReturned );
This method returns the standard values, as well as the following:
For other return values, see ADSI Error Codes.
ADSI allocates the memory for the array of ADS_ATTR_INFO, as pointed to by ppAttributeEntries. However, the caller must call FreeADsMem to free the array. The order of attributes returned in ppAttributeEntries may not necessarily be the same as requested in pAttributeName.
The following C++ code snippet shows how the IDirectoryObject::GetObjectAttribute method can be used.
HRESULT hr; ADS_ATTR_INFO *pAttrInfo=NULL; DWORD dwReturn; LPWSTR pAttrNames[]={L"givenName",L"sn", L"otherTelephone" }; DWORD dwNumAttr=sizeof(pAttrNames)/sizeof(LPWSTR); IDirectoryObject *pDirObject=NULL; hr=ADsGetObject(L"LDAP://CN=Neil Smith,OU=Sales,DC=Microsoft,DC=com", IID_IDirectoryObject, (void**) &pDirObject ); ///////////////////////////////////////// // Get attribute values requested // Note: The order is not necessarily the // same as requested using pAttrNames. /////////////////////////////////////////// hr = pDirObject->GetObjectAttributes( pAttrNames, dwNumAttr, &pAttrInfo, &dwReturn ); if ( SUCCEEDED(hr) ) { for(DWORD idx=0; idx < dwReturn;idx++, pAttrInfo++ ) { if ( _wcsicmp(pAttrInfo->pszAttrName,L"givenName") == 0 ) { printf("First Name: %S\n", pAttrInfo->pADsValues->CaseIgnoreString); } else if ( _wcsicmp(pAttrInfo->pszAttrName, L"sn") == 0 ) { printf("Last Name: %S\n", pAttrInfo->pADsValues->CaseIgnoreString); } else if ( _wcsicmp(pAttrInfo->pszAttrName, L"otherTelephone") == 0 ) { //Print out multi-valued property, "Other Telephones". printf("Other Telephones:"); for (DWORD val=0; val < pAttrInfo->dwNumValues; val++, pAttrInfo->pADsValues++) { printf(" %S\n", pAttrInfo->pADsValues->CaseIgnoreString); } } } } pDirObject->Release(); ///////////////////////////////////////////////////////////// // Use FreeADsMem for all memory obtained from the ADSI call. ///////////////////////////////////////////////////////////// FreeADsMem( pAttrInfo );
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.
IDirectoryObject, ADS_ATTR_INFO, FreeADsMem, ADSI Error Codes