Share via


IADsPropertyList::Item, méthode (iads.h)

La méthode IADsPropertyList::Item récupère l’élément de propriété spécifié à partir de la liste.

Syntaxe

HRESULT Item(
  [in]      VARIANT varIndex,
  [in, out] VARIANT *pVariant
);

Paramètres

[in] varIndex

VARIANT qui contient l’index ou le nom de la propriété à récupérer.

[in, out] pVariant

Adresse d’une variable VARIANT allouée par l’appelant. En retour, le VARIANT contient le pointeur IDispatch vers l’objet qui implémente l’interface IADsPropertyEntry pour l’attribut récupéré.

Valeur retournée

Cette méthode prend en charge les valeurs de retour HRESULT standard, y compris les S_OK. Pour plus d’informations et d’autres valeurs de retour, consultez Codes d’erreur ADSI.

Notes

Vous devez effacer pVariant à l’aide deVariantClear lorsque la valeur retournée par la méthode Item n’est plus requise.

Exemples

L’exemple de code suivant montre comment énumérer toutes les entrées avec la méthode Item .

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

L’exemple de code suivant montre comment récupérer la propriété Owner d’un ordinateur à l’aide de la méthode IADsPropertyList::Item . Pour plus d’informations sur la fonction GetPropertyCache et un exemple de code, consultez IADsPropertyList.

////////////////////////////////////////
// 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(&varItem);
    VariantInit(&varEntry);
 
    // get a property entry
    V_BSTR(&varItem)= SysAllocString(item);
    V_VT(&varItem)=VT_BSTR;
    HRESULT hr = pList->Item(varItem ,&varEntry);
    hr = V_DISPATCH(&var)->QueryInterface(
                        IID_IADsPropertyEntry,
                        (void**)&pEntry);
    VariantClear(&varItem);
    VariantClear(&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->get_Name(&bstr);
    if(SUCCEEDED(hr))
    {
        SysFreeString(bstr);
    }
    printf(" Name : %S\n", bstr);
 
    pEntry->get_ADsType(&ln);
    if(SUCCEEDED(hr))
    {
        printf(" Type : %d\n", ln);
    }
 
    pEntry->get_ControlCode(&ln); 
    if(SUCCEEDED(hr))
    {
        printf(" Code %d\n",ln);
    }
}

Configuration requise

   
Client minimal pris en charge Windows Vista
Serveur minimal pris en charge Windows Server 2008
Plateforme cible Windows
En-tête iads.h
DLL Activeds.dll

Voir aussi

Codes d’erreur ADSI

IADsPropertyEntry

IADsPropertyList

Méthodes de propriété IADsPropertyList

IDispatch