Export (0) Print
Expand All

IADsADSystemInfo::GetTrees method

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

Syntax


HRESULT GetTrees(
  [out]  VARIANT *pvTrees
);

Parameters

pvTrees [out]

A Variant array of strings that contains the names of the directory trees within the forest.

Return value

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

Examples

The following C++ code example retrieves the names of the directory trees within the forest the Windows 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 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 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

Minimum supported client

Windows Vista

Minimum supported server

Windows Server 2003

Header

Iads.h

DLL

Activeds.dll

IID

IID_IADsADSystemInfo is defined as 5BB11929-AFD1-11D2-9CB9-0000F87A369E

See also

IADsADSystemInfo
ADSI Error Codes

 

 

Show:
© 2014 Microsoft