HOWTO: Find All ADSI Providers on a SystemID: Q233023
|
Microsoft Active Directory Service Interfaces (ADSI) is built on a provider model, where clients interact with ADSI interfaces to perform directory manipulation, while providers implement the mapping between the directory and ADSI interfaces.
This article shows you how to find and list all ADSI providers on a system.
This can be accomplished by enumerating ADs namespace members with the following code for both Microsoft Visual C++ and Microsoft Visual Basic.
#include <activeds.h>
#include <stdio.h>
// link with activeds.lib and adsiid.lib
void main()
{
IEnumVARIANT *pEnum;
IADsContainer *pCont;
IADs *pADs;
IDispatch *pDisp;
VARIANT var;
BSTR bstr;
ULONG lFetch;
HRESULT hr;
// Skipping error checking for simplicity
CoInitialize(NULL);
// Bind to ADs namespace
hr = ADsGetObject(L"ADs:",IID_IADsContainer, (void**) &pCont);
//Create an enumerator object in the container.
hr=ADsBuildEnumerator(pCont, &pEnum);
// Now enumerate through all providers
while(hr == S_OK)
{
hr = ADsEnumerateNext(pEnum, 1, &var, &lFetch);
if (lFetch == 1)
{
pDisp = V_DISPATCH(&var);
pDisp->QueryInterface(IID_IADs, (void**)&pADs);
pDisp->Release();
pADs->get_Name(&bstr);
printf("%S\n",(LPWSTR)bstr);
pADs->Release();
SysFreeString(bstr);
}
}
//Release the enumerator.
if (pEnum != NULL)
{
ADsFreeEnumerator(pEnum);
}
}
Dim prov As IADsNamespaces
Dim member As IADs
Set prov = GetObject("ADs:")
For Each member In prov
Debug.Print member.Name
Next
For additional information about ADSI, please visit:
http://www.microsoft.com/adsi
Additional query words:
Keywords : kbADSI kbVBp kbVC kbGrpPlatform
Version : winnt:2.0,2.5
Platform : winnt
Issue type : kbhowto
Last Reviewed: July 2, 1999