Platform SDK: Active Directory, ADSI, and Directory Services |
The IADsADSystemInfo::GetTrees method retrieves the names of the directory trees within the forest the Windows® 2000 system belongs to.
HRESULT IADsADSystemInfo::GetTrees( VARIANT *pvTrees );
This method supports the standard HRESULT return values. For more information, see ADSI Error Codes.
The following C++ code snippet 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); IADsWinNTSystemInfo *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 snippet 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 snippet 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 %>
Windows NT/2000: Requires Windows 2000.
Windows 95/98: Unsupported.
Header: Declared in Iads.h.