Directory Services |
The IADsADSystemInfo::GetTrees method retrieves the DNS names of all the directory trees in the local computer's forest.
HRESULT GetTrees( VARIANT* pvTrees );
This method supports the standard HRESULT return values. For more information, see ADSI Error Codes.
The following C++ code example retrieves the names of the directory trees within the forest the Windows 2000 system belongs to. For brevity, error checking is omitted.
#include <activeds.h> #include <stdio.h> int main() { HRESULT hr; hr = CoInitialize(NULL); IADsADSystemInfo *pSys; hr = CoCreateInstance(CLSID_ADSystemInfo, NULL, CLSCTX_INPROC_SERVER, IID_IADsADSystemInfo, (void**)&pSys); VARIANT var; VariantInit(&var); hr = pSys->GetTrees(&var); LONG lstart, lend; SAFEARRAY *sa = V_ARRAY( &var ); VARIANT varItem; // Get the lower and upper bound. hr = SafeArrayGetLBound( sa, 1, &lstart ); hr = SafeArrayGetUBound( sa, 1, &lend ); // Now iterate and print the content. VariantInit(&varItem); printf("Getting Name of Directory Trees :\n"); for ( long idx=lstart; idx <= lend; idx++ ) { hr = SafeArrayGetElement( sa, &idx, &varItem ); printf("%S ", V_BSTR(&varItem)); VariantClear(&varItem); } VariantClear(&var);} if(pSys) { pSys->Release(); } CoUninitialize(); return 0; }
The following Visual Basic code example retrieves the names of the directory trees within the forest that the Windows 2000 system belongs to.
Dim sys As New ADSystemInfo For Each var In sys.GetTrees Debug.Print "Tree: " & var Next var
The following VBScript/ASP code example retrieves the names of the directory trees within the forest the Windows 2000 that the system belongs to.
<% Dim sys Set sys = Server.CreateObject("ADSystemInfo") For Each var tree in sys.GetTrees Response.Write "Tree: " & var Next var %>
Client: Included in Windows XP and
Windows 2000 Professional.
Server: Included in Windows Server 2003 and
Windows 2000 Server.
Header: Declared in Iads.h.