Platform SDK: Active Directory, ADSI, and Directory Services

IADsADSystemInfo::GetTrees

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
);

Parameters

pvTrees
[out, retval] A Variant array of strings that contains the names of the directory trees within the forest.

Return Values

This method supports the standard HRESULT return values. For more information, see ADSI Error Codes.

Example Code [C++]

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;
}

Example Code [Visual Basic]

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

Example Code [VBScript]

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
%>

Requirements

  Windows NT/2000: Requires Windows 2000.
  Windows 95/98: Unsupported.
  Header: Declared in Iads.h.

See Also

IADsADSystemInfo, ADSI Error Codes