Querying Computer Properties: The IADsComputer Interface

   

Querying Computer Properties: The IADsComputer Interface

Using the IADsComputer interface you can query various properties of a machine, including the Hardware Abstraction Layer (HAL) in use and the owner and registered organization of the machine. Unlike Registry editing tools used to manipulate these properties, all properties of ADSI's IADsComputer interface found within the Windows NT service provider are read-only.

For this reason, this interface is well suited for gathering statistics about the enterprise or controlling program flow, as opposed to the programmatic enterprise administration you have been performing in previous chapters. If you wish to manipulate the values of the interface properties, you will have to use traditional methods , such as REGEDT32.

By combining enumeration functions with IADsComputer property queries, you can generate reports regarding the status of an upgrade, or determine older technology in use in the environment by examining the appropriate properties.

Tip

As described in Chapter 3, "Container Enumeration Methods and Programmatic Domain Account Policy Manipulation," a "Computer" filter on the IADsContainer interface can allow all computers in a resource domain to be enumerated .


Querying the Computer Owner Using Visual Basic

You can derive a computer's primary user by querying the RegisteredOwner string in the Registry. While you can use REGEDIT/REGEDT32 to query a single remote Registry for these values, you can use ADSI to perform this query on large quantities of machines using the following Visual Basic code with an enumeration function:

 Dim Computer as IADsComputer Dim ComputerName as String Dim ComputerDomain as String ComputerDomain = "  Target_Computer_Domain  " ComputerName = "  Target_Computer_Name  " Set Computer= GetObject("WinNT://" & ComputerDomain &"/" & ComputerName & ",computer") Dim RetVal as String RetVal = Computer.Owner Debug.Print RetVal 

Querying the Registered Organization Using Visual Basic

Using similar Visual Basic code to that which was used to query the computer owner, you can query the RegisteredOrganization string value in the Registry, as follows :

 Dim Computer as IADsComputer Dim ComputerName as String Dim ComputerDomain as String ComputerDomain = "  Target_Computer_Domain  " ComputerName = "  Target_Computer_Name  " Set Computer= GetObject("WinNT://" & ComputerDomain&"/" & ComputerName & ",computer") Dim RetVal as String RetVal = Computer.Division Debug.Print RetVal 

Querying the Computer Operating System Using Visual Basic

You can also find the current name of the operating system for any given machine using the following Visual Basic code:

 Dim Computer as IADsComputer Dim ComputerName as String Dim ComputerDomain as String ComputerDomain = "  Target_Computer_Domain  " ComputerName = "  Target_Computer_Name  " Set Computer= GetObject("WinNT://" & ComputerDomain & "/" & ComputerName & ",computer") Dim RetVal as String RetVal = Computer.OperatingSystem Debug.Print RetVal 

Note

When run against a Windows NT workstation, this code segment simply returns the string Windows NT .


Querying the Computer Operating System Version Using Visual Basic

In conjunction with the OperatingSystemVersion property of the IADsComputer interface, you can also find the version number of Windows for any given machine using the following Visual Basic code:

 Dim Computer as IADsComputer Dim ComputerName as String Dim ComputerDomain as String ComputerDomain = "  Target_Computer_Domain  " ComputerName = "  Target_Computer_Name  " Set Computer= GetObject("WinNT://" & ComputerDomain&"/" & ComputerName & ",computer") Dim RetVal as String RetVal = Computer.OperatingSystemVersion Debug.Print RetVal 

Note

This code will output the major and minor revision numbers of the installed operating system, for instance 4.0 for Windows NT Workstation 4.0 .


Querying the Computer Processor Type Using Visual Basic

Using the Processor property of the IADsComputer interface, you can determine the processor architecture (Alpha or x86) as well as the family, model, and stepping of the installed processor(s). Use the following Visual Basic code to determine the processor architecture:

 Dim Computer as IADsComputer Dim ComputerName as String Dim ComputerDomain as String ComputerDomain = "  Target_Computer_Domain  " ComputerName = "  Target_Computer_Name  " Set Computer= GetObject("WinNT://" & ComputerDomain & "/" & ComputerName & ",computer") Dim RetVal as String RetVal = Computer.Processor Debug.Print RetVal 

Note

This code will output the processor type (x86 or Alpha) as well as the family, model, and stepping of the processor, such as x86 Family 5 Model 4 Stepping 3 .


Querying the Installed HAL on Windows NT Using Visual Basic

Despite its name, the ProcessorCount property does not yield an integer representing the physical number of processors installed in the system, but rather shows the HAL in use on the system. Use the following Visual Basic code to query the HAL in use:

 Dim Computer as IADsComputer Dim ComputerName as String Dim ComputerDomain as String ComputerDomain = "  Target_Computer_Domain  " ComputerName = "  Target_Computer_Name  " Set Computer= GetObject("WinNT://" & ComputerDomain&"/" & ComputerName & ",computer") Dim RetVal as String RetVal = Computer.ProcessorCount Debug.Print RetVal 

   
Top


Windows NT. 2000 ADSI Scripting for System Administration
Windows NT/2000 ADSI Scripting for System Administration
ISBN: 1578702194
EAN: 2147483647
Year: 2000
Pages: 194
Authors: Thomas Eck

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net