| Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsPropertyList::GetPropertyItem method retrieves the item that matches the name from the list.
HRESULT GetPropertyItem( BSTR bstrName, LONG lnADsType, VARIANT * pVariant );
This method supports the standard HRESULT return values, including S_OK. For other return values, see ADSI Error Codes.
As a caller, you are responsible for freeing the VARIANT variable allocated by GetPropertyItem.
The following Visual Basic code snippet shows how to retrieve a property entry using the GetPropertyItem method.
Dim propList As IADsPropertyList
Dim propEnty As IADsPropertyEntry
Dim propVal As IADsPropertyValue
Set propList = GetObject("LDAP://dc01/DC=Microsoft,DC=com")
propList.GetInfo
Set propEntry = propList.GetPropertyItem("dc", ADSTYPE_CASE_IGNORE_STRING)
For Each v In propEntry.Values
Set propVal = v
Debug.Print propVal.CaseIgnoreString
Next
The following C++ code snippet shows how to retrieve a property entry using the GetPropertyItem method. It assumes that the IADsPropertyList interface has been properly obtained. For more information on how to load the property cache, see the code listing of the GetPropertyCache(LPWSTR) function given in IADsPropertyList.
#include <activeds.h>
#include <stdio.h>
/////////////////////////////////////////////////////////
// Function to retrieve a specified property entry
// using the IADsPropertyList::GetPropertyItem method.
/////////////////////////////////////////////////////////
IADsPropertyEntry *GetPropertyItem(
IADsPropertyList *pList,
LPWSTR entryName,
long entryType)
{
IADsPropertyEntry *pEntry;
VARIANT var;
VariantInit(&var);
// get a property entry
hr = pList->GetPropertyItem(entryName, entryType, &var);
hr = V_DISPATCH(&var)->QueryInterface(IID_IADsPropertyEntry,
(void**)&pEntry);
VariantClear(&var);
return pEntry;
}
///////////////////////////////////////////////////////
// Examine a property entry.
///////////////////////////////////////////////////////
IADsPropertyList *pList;
pList = GetPropertyCache(L"LDAP://dc01/DC=Microsoft,DC=COM");
IADsPropertyEntry *pEntry;
pEntry = GetPropertyItem(pList, L"dc", ADSTYPE_CASE_IGNORE_STRING)
BSTR nm;
HRESULT hr = pEntry->get_Name(&nm);
printf("Property name = %S\n",nm);
if(pList) pList->Release();
if(pEntry) pEntry->Release();
if(nm) SysFreeString(&nm);
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.
ADSI Error Codes, ADSTYPEENUM, IADsPropertyList, IADsPropertyList Property Methods