Directory Services

IADsADSystemInfo::GetTrees

The IADsADSystemInfo::GetTrees method retrieves the DNS names of all the directory trees in the local computer's forest.

HRESULT GetTrees( 
  VARIANT* pvTrees
);

Parameters

pvTrees
[out] 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 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;
}

Example Code [Visual Basic]

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

Example Code [VBScript]

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

Requirements

Client: Included in Windows XP and Windows 2000 Professional.
Server: Included in Windows Server 2003 and Windows 2000 Server.
Header: Declared in Iads.h.

See Also

IADsADSystemInfo, ADSI Error Codes