Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsPropertyList::Item method retrieves the specified property item from the list.
HRESULT Item( VARIANT varIndex, 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 Item. The following Visual Basic code snippet shows how to enumerate all the entries with the Item method.
Dim propList As IADsPropertyList Dim propEnty As IADsPropertyEntry Dim count As Long Set propList = GetObject("LDAP://dc02/ DC=Microsoft,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
The following C++ code snippet shows how to retrieve the Owner property of a computer using the IADsPropertyList::Item method.
//////////////////////////////////////// // 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; 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"); long ln; BSTR bstr; pEntry->get_Name(&bstr); printf(" Name : %S\n", bstr); pEntry->get_ADsType(&ln); printf(" Type : %d\n", ln); pEntry->get_ControlCode(&ln); printf(" Code %d\n",ln);
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, IADsPropertyEntry, IADsPropertyList, IADsPropertyList Property Methods