读取架构
大多数提供程序都支持 Active Directory 附带的架构。 架构包含类和属性定义。 ADSI 在“Provider://schema”中对架构进行了抽象化。 每个对象都带有定义其类别的架构位置。 你可以使用 IADs::get_Class 属性方法来获取这些信息。
要绑定到特定域上的架构容器,请执行以下操作:
Dim SchemaContainer As Object
Set SchemaContainer = GetObject("LDAP://Fabrikam/Schema")
hr = ADsGetObject(L"LDAP://Fabrikam/Schema", IID_IADsContainer, (void**) &pSchema );
要列出架构容器中的信息,请绑定到容器并枚举容器中的每个对象,如下图所示:
Dim prop As Object
Dim obj As Object
Dim SchemaContainer As Object
Dim Class As Object
Set SchemaContainer = GetObject("LDAP://Fabrikam/Schema")
'Show all items in the schema container
For Each obj In SchemaContainer
Debug.Print obj.Name & " (" & obj.Class & ")"
Next
'Show the optional attributes
For Each prop In Class.OptionalProperties
Debug.Print prop
Next
IADsContainer *pSchema=NULL;
HRESULT hr;
CoInitialize(NULL);
hr = ADsGetObject(L"LDAP://Fabrikam/Schema",
IID_IADsContainer, (void**) &pSchema );
if ( !SUCCEEDED(hr) )
{
return hr;
}
// Enumerate schema objects
IEnumVARIANT *pEnum = NULL;
hr = ADsBuildEnumerator( pSchema, &pEnum );
pSchema->Release(); // This is no longer needed, since we have the enumerator already.
if ( SUCCEEDED(hr) )
{
VARIANT var;
ULONG lFetch;
IADs *pChild=NULL;
VariantInit(&var);
while( SUCCEEDED(ADsEnumerateNext( pEnum, 1, &var, &lFetch )) && lFetch == 1 )
{
hr = V_DISPATCH(&var)->QueryInterface( IID_IADs, (void**) &pChild );
if ( SUCCEEDED(hr) )
{
BSTR bstrName;
BSTR bstrClass;
// Get more information on the child classes
pChild->get_Name(&bstrName);
pChild->get_Class(&bstrClass);
printf("%S\t\t(%S)\n", bstrName, bstrClass );
// Clean-up
SysFreeString(bstrName);
SysFreeString(bstrClass);
pChild->Release();
}
VariantClear(&var);
}
}
CoUninitialize();
你还可以绑定到一个对象并获取架构位置,如下所示:
Dim prop As Object
Dim dom As Object
Dim Class As Object
Set dom = GetObject("LDAP://Fabrikam")
Debug.Print dom.Schema
Set Class = GetObject(dom.Schema)
'Mandatory attributes
For Each prop In Class.MandatoryProperties
Debug.Print prop
Next