IADsPropertyList::Item method

The IADsPropertyList::Item method retrieves the specified property item from the list.

Syntax

HRESULT Item(
  VARIANT varIndex,
  VARIANT *pVariant
);

Parameters

varIndex

The VARIANT that contains the index or name of the property to be retrieved.

pVariant

Address of a caller-allocated VARIANT variable. On return, the VARIANT contains the IDispatch pointer to the object which implements the IADsPropertyEntry interface for the attribute retrieved.

Return Value

This method supports the standard HRESULT return values, including S_OK. For more information and other return values, see ADSI Error Codes.

Remarks

You must clear pVariant using VariantClear when the value returned by the Item method is no longer required.

Examples

The following code example shows how to enumerate all the entries with the Item method.

VB
Dim propList As IADsPropertyList
Dim propEntry As IADsPropertyEntry
Dim count As Long

On Error GoTo Cleanup

Set propList = GetObject("LDAP://dc02/DC=Fabrikam,DC=com")

propList.GetInfo count = propList.PropertyCount Debug.Print "No of Property Found: " & count

'==== Getting the property list item with Name ================== Set propEntry = propList.Item("uSNCreated") Debug.Print propEntry.Name Debug.Print propEntry.ADsType

' to examine property entries by name and type For i = 0 To count - 1 '==== Getting the property list item with Number ============= Set propEntry = propList.Item(i) Debug.Print propEntry.Name Debug.Print propEntry.ADsType Next

Cleanup: If (Err.Number<>0) Then MsgBox("An error has occurred. " & Err.Number) End If

Set propList = Nothing
Set propEntry = Nothing
The following code example shows how to retrieve the Owner property of a computer using the IADsPropertyList::Item method. For more information about the GetPropertyCache function and a code example, see IADsPropertyList.
C++
////////////////////////////////////////
// function:    PropertyItem
//    input:    PropertyList, 
//              name of the item
//   output:    Property entry
//     uses:    IADsPropertyList::Item
////////////////////////////////////////
IADsPropertyEntry *PropertyItem(
         IADsPropertyList *pList,
         LPWSTR item)
{
    IADsPropertyEntry *pEntry;
    VARIANT varEntry, varItem;
if(!pList || !item)
{
    _tprintf(TEXT("Invalid parameter..."));
    return NULL;
}

VariantInit(&amp;varItem);
VariantInit(&amp;varEntry);

// get a property entry
V_BSTR(&amp;varItem)= SysAllocString(item);
V_VT(&amp;varItem)=VT_BSTR;
HRESULT hr = pList-&gt;Item(varItem ,&amp;varEntry);
hr = V_DISPATCH(&amp;var)-&gt;QueryInterface(
                    IID_IADsPropertyEntry,
                    (void**)&amp;pEntry);
VariantClear(&amp;varItem);
VariantClear(&amp;varEntry);
return pEntry;

}

/////////////////////////////////////// // examine a property entry /////////////////////////////////////// IADsPropertyList *pList; pList=GetPropertyCache(L"WinNT://myComputer,computer");

IADsPropertyEntry *pEntry; pEntry = PropertyItem(pList, L"Owner");

if(pEntry) { HRESULT hr; BSTR bstr; long ln;

hr = pEntry-&gt;get_Name(&amp;bstr);
if(SUCCEEDED(hr))
{
    SysFreeString(bstr);
}
printf(" Name : %S\n", bstr);

pEntry-&gt;get_ADsType(&amp;ln);
if(SUCCEEDED(hr))
{
    printf(" Type : %d\n", ln);
}

pEntry-&gt;get_ControlCode(&amp;ln); 
if(SUCCEEDED(hr))
{
    printf(" Code %d\n",ln);
}

}

Requirements

   
Windows version Windows Vista Windows Server 2008
Target Platform Windows
Header iads.h
DLL Activeds.dll

See Also

ADSI Error Codes

IADsPropertyEntry

IADsPropertyList

IADsPropertyList Property Methods

IDispatch