Directory Services |
The following code examples show how to use the IADsPropertyList, IADsPropertyEntry, and IADsPropertyValue interfaces.
[C++]
HRESULT hr;
BSTR bstr;
VARIANT var;
IDispatch *pDispatch;
IADsPropertyList *pPropList;
IADsPropertyEntry *pEntry;
IADsPropertyValue *pValue;
LONG lADsType;
IADs *pADs=NULL;
//////////////////////////////////////////////////
// Note: For brevity, error handling is omitted.
//////////////////////////////////////////////////
hr = ADsGetObject(L"LDAP://DC=Sales,DC=Fabrikam,DC=Com", IID_IADs, (void**) &pADs );
///////////////////////////////////////////////////////////////////
// Retrieve objects prior to calling IADsProperty* methods.
///////////////////////////////////////////////////////////////////
hr = pADs->GetInfo();
hr = pADs->QueryInterface( IID_IADsPropertyList, (void**) &pPropList );
pADs->Release();
//////////////////////////////////////////////////
// Get the DC property.
//////////////////////////////////////////////////
hr = pPropList->GetPropertyItem( CComBSTR("dc"), ADSTYPE_CASE_IGNORE_STRING, &var );
if ( SUCCEEDED(hr) )
{
//////////////////////////////////////////
// Get the IADsPropertyEntry interface.
//////////////////////////////////////////
pDispatch = V_DISPATCH( &var );
hr = pDispatch->QueryInterface( IID_IADsPropertyEntry, (void**) &pEntry );
VariantClear( &var );
if ( SUCCEEDED(hr) )
{
VARIANT varValueArray;
VARIANT varValue;
long idx=0;
///////////////////////////////////////////////
// get_Values return array of VT_DISPATCH.
///////////////////////////////////////////////
hr = pEntry->get_Values( &varValueArray );
hr = pEntry->get_ADsType( &lADsType);
hr = SafeArrayGetElement( V_ARRAY( &varValueArray ), &idx, &varValue );
pEntry->Release(); // Release entry.
/////////////////////////////////////
// IADsPropertyValue
/////////////////////////////////////
pDispatch = (IDispatch*) V_DISPATCH(&varValue);
hr = pDispatch->QueryInterface( IID_IADsPropertyValue,
(void**) &pValue );
pDispatch->Release();
/////////////////////////////
// Display the value
/////////////////////////////
hr = pValue->get_CaseIgnoreString( &bstr);
printf("%S\n", bstr );
SysFreeString( bstr );
pValue->Release();
}
}
Visual Basic Example 1
[Visual Basic]
Dim propList As IADsPropertyList
Dim propEntry As IADsPropertyEntry
Dim propVal As IADsPropertyValue
Dim sName As String
Set propList = GetObject("LDAP://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
Visual Basic Example 2
[Visual Basic]
'Visual Basic Sample: Enumerating properties in the property list.
Dim propList As IADsPropertyList
Dim propEntry As IADsPropertyEntry
Dim propVal As IADsPropertyValue
Dim count As Long
Set propList = GetObject("LDAP://dc01/DC=Fabrikam,DC=com")
propList.GetInfo
count = propList.PropertyCount
Debug.Print "No of Property Found: " & count
For i = 0 To count - 1
'Each item in property list has a property entry.
Set propEntry = propList.Item(i)
Debug.Print propEntry.Name
Debug.Print propEntry.ADsType
'Each value in property entry has property values.
For Each v In propEntry.Values
Set propVal = v
Debug.Print propVal.ADsType
Next
Next