Identifying the Name and Version Number of the Operating System

Microsoft® Windows® 2000 Scripting Guide

microsoft windows 2000 scripting guide

« Previous | Next »   

Operating systems vary in the capabilities they support; newer operating systems typically support more features and have more capabilities than older operating systems. For example, scripts that run on a Windows 2000 operating system might not run on an earlier version of Windows. This is because many new WMI classes were introduced in Windows 2000.

You can use the WMI Win32_OperatingSystem class to return both the name and the version number of the operating system running on a computer. For example, the following information is returned from a computer running Windows 2000 Professional:

Microsoft Windows 2000 Professional 5.0.2600 

The kind of information you need to collect can affect whether you need to retrieve both the name and the version number. To distinguish between products with different names, you can retrieve either the product name or the version number. To distinguish between products with the same version number, you must retrieve the name.

Table 8.7 lists the names and version numbers for a selected subset of Windows operating systems.

Table 8.7   Windows Operating System Names and Version Numbers

NameVersion Number
Microsoft Windows 2000 Professional5.0.2195
Microsoft Windows 2000 Server5.0.2195
Microsoft® Windows® XP Home Edition5.1.2600
Microsoft® Windows® XP Professional5.1.2600

The properties of the WMI Win32_OperatingSystem class used to retrieve the operating system name and version number of each operating system installed on a computer are listed in Table 8.8.

Table 8.8   Win32_OperatingSystem Properties

PropertyDescription
CaptionName of the operating system.
VersionVersion number of the operating system.

Scripting Steps

Listing 8.6 contains a script that identifies the name and version number of the operating system installed on a computer. To carry out this task, the script must perform the following steps:

  1. Create a variable to specify the computer name.
  2. Use a GetObject call to connect to the WMI namespace root\cimv2, and set the impersonation level to "impersonate."
  3. Use the ExecQuery method to query the Win32_OperatingSystem class.

    This query returns a collection consisting of all the operating systems installed on the computer.

  4. For each operating system in the collection, echo the name and version number.

Listing 8.6   Identifying the Name and Version Number of the Operating System

1 2 3 4 5 6 7 8 
strComputer = "." Set objWMIService = GetObject("winmgmts:" _     & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") Set colOperatingSystems = objWMIService.ExecQuery _     ("SELECT * FROM Win32_OperatingSystem") For Each objOperatingSystem in colOperatingSystems     Wscript.Echo objOperatingSystem.Caption, objOperatingSystem.Version Next

send us your feedback Send us your feedback « Previous | Next »   


Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003
ISBN: N/A
EAN: N/A
Year: 2004
Pages: 635

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