Working with IADsADSystemInfoIn 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.
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.
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 ![]() |