Previous Page
Next Page

Working with IADsADSystemInfo

In this section, you will use the IADsADSystemInfo interface to obtain data about the local computer. The IADsADSystemInfo interface is implemented to provide access to the ADSystemInfo class. Because this class resides in the Adsldp.dll file, which is part of ADSI, it is present on Microsoft Windows Server 2003, Windows XP, and even Windows 2000. To use IADsADSystemInfo, you need to create the object by creating an instance of the ADSystemInfo class. This process is actually simpleyou use the CreateObject command. Table 16-1 summarizes the nine properties exposed by IADsADSystemInfo.

Table 16-1. Properties Exposed by IADsADSystemInfo

Property

Meaning

ComputerName

Retrieves the distinguished name of the local computer

DomainDNSName

Retrieves the Domain Name System (DNS) name of the local computer's domain

DomainShortName

Retrieves the short name of the local computer's domain (the network basic input/output system [NetBIOS] version of the name)

ForestDNSName

Retrieves the DNS name of the local computer's forest

IsNativeMode

Determines whether the local computer's domain is native or mixed mode

PDCRoleOwner

Retrieves the distinguished name of the domain controller (DC) that owns the primary domain controller (PDC) emulator role in the local computer's domain

SchemaRoleOwner

Retrieves the distinguished name of the Schema Master in the local computer's forest

SiteName

Retrieves the site name in which the local computer resides

UserName

Retrieves the distinguished name of the currently logged-on user


The advantage of using IADsADSystemInfo over other means of gaining user and computer information is that IADsADSystemInfo retrieves fully qualified domain names, which are immediately useful when working with Active Directory. In addition to the nine properties listed in Table 16-1, IADsADSystemInfo provides 13 methods. However, most of these methods duplicate the properties listed in Table 16-1, so Table 16-2 describes only the methods that provide additional information.

Table 16-2. IADsADSystemInfo Methods Providing Unique Information

Method

Description

GetAnyDCName

Retrieves the DNS name of a domain controller in the local computer's domain

RefreshSchemaCache

Refreshes ADSI's Active Directory schema cache on the local computer

GetTrees

Retrieves the DNS names of all the directory trees in the local computer's forest; returned as an array


The following script, called SysInfo.vbs, illustrates using the IADsADSystemInfo interface. In the first line, you use objSysInfo to hold the object that comes back when you use CreateObject to create an instance of ADSystemInfo. After you do this, you use the RefreshSchemaCache method to refresh the Active Directory schema cache that is resident on the local computer. Performing this step ensures that you are working with the most recent copy of the Active Directory schema. After refreshing the schema cache on the local machine, you echo out the pertinent information. The only step that is a little tricky is the use of For Each...Next to walk through the array that is returned when you use the GetTrees method. This step is required, even when only one domain is present in the forest.

SysInfo.vbs

Set objSysInfo = CreateObject("ADSystemInfo")
objSysInfo.RefreshSchemaCache
WScript.Echo "User name: " & objSysInfo.UserName
WScript.Echo "Computer name: " & objSysInfo.ComputerName
WScript.Echo "Site name: " & objSysInfo.SiteName
WScript.Echo "Domain short name: " & objSysInfo.DomainShortName
WScript.Echo "Domain DNS name: " & objSysInfo.DomainDNSName
WScript.Echo "Forest DNS name: " & objSysInfo.ForestDNSName
WScript.Echo "PDC role owner: " & objSysInfo.PDCRoleOwner
WScript.Echo "Schema role owner: " & objSysInfo.SchemaRoleOwner
WScript.Echo "Domain is in native mode: " & objSysInfo.IsNativeMode
WScript.Echo "Active Directory DomainController: " & objSysInfo.GetAnyDCName

For Each tree In objSysInfo.GetTrees
  WScript.Echo "Domain trees: " & tree
Next


Previous Page
Next Page