Directory Services |
The IADsPropertyList::GetPropertyItem method retrieves the item that matches the name from the list.
HRESULT GetPropertyItem( BSTR bstrName, LONG lnADsType, VARIANT* pVariant );
Any memory allocated for this parameter must be released with the VariantClear function when the data is no longer required.
The following code example shows how to retrieve a property entry using the GetPropertyItem method.
[Visual Basic]
Dim propList As IADsPropertyList
Dim propEntry As IADsPropertyEntry
Dim propVal As IADsPropertyValue
On Error GoTo Cleanup
Set propList = GetObject("LDAP://dc01/DC=Fabrikam,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
Cleanup:
If (Err.Number<>0) Then
MsgBox("An error has occurred. " & Err.Number)
End If
Set propList = Nothing
Set propEntry = Nothing
Set propVal = Nothing
The following code example shows how to retrieve a property entry using the GetPropertyItem method. It assumes that the IADsPropertyList interface has been properly obtained. For more information about how to load the property cache, see the GetPropertyCache example function in IADsPropertyList.
[C++]
#include <activeds.h>
#include <stdio.h>
/////////////////////////////////////////////////////////
// Function to retrieve a specified property entry
// using the IADsPropertyList::GetPropertyItem method.
/////////////////////////////////////////////////////////
IADsPropertyEntry *GetPropertyItem(
IADsPropertyList *pList,
BSTR entryName,
long entryType)
{
IADsPropertyEntry *pEntry;
VARIANT var;
VariantInit(&var);
if(!pList || !entryName)
{
_tprintf("Invalid argument...");
return NULL;
}
// 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 = NULL;
IADsPropertyEntry *pEntry = NULL;
pList = GetPropertyCache(L"LDAP://dc01/DC=Fabrikam,DC=COM");
if(pList)
{
pEntry = GetPropertyItem(pList, L"dc", ADSTYPE_CASE_IGNORE_STRING);
}
if(pEntry)
{
BSTR nm;
HRESULT hr = pEntry->get_Name(&nm);
if(SUCCEEDED(hr))
{
printf("Property name = %S\n",nm);
SysFreeString(nm);
}
}
if(pList)
pList->Release();
if(pEntry)
pEntry->Release();
Client: Included in Windows XP and
Windows 2000 Professional.
Server: Included in Windows Server 2003 and
Windows 2000 Server.
Redistributable: Requires Active Directory Client Extension
on Windows NT 4.0 SP6a and Windows 95/98/Me.
Header: Declared in Iads.h.
ADSTYPEENUM, VariantClear, ADSI Error Codes, IADsPropertyList, IADsPropertyList Property Methods, IDispatch