Identifying the Name and Version Number of the Operating System

Microsoft® Windows® 2000 Scripting Guide

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

Name

Version Number

Microsoft Windows 2000 Professional

5.0.2195

Microsoft Windows 2000 Server

5.0.2195

Microsoft® Windows® XP Home Edition

5.1.2600

Microsoft® Windows® XP Professional

5.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

Property

Description

Caption

Name of the operating system.

Version

Version 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