Microsoft Windows 2000 Scripting Guide(c) Automating System Administration 2003

Microsoft® Windows® 2000 Scripting Guide

« Previous | Next »   

Service packs represent changes that have been made to the base operating system since the time the operating system was first released. These changes can include fixes to known problems, updates to device drivers, new tools, and enhanced functionality.

Knowing which service packs have been installed on a computer is important for several reasons. For example:

Service packs are released on an as-needed basis and are cumulative. For example, when Service Pack 3 for a version of Windows is released, it contains all the updates that were included in Service Packs 1 and 2. Installing Service Pack 3 provides all the benefits of the new service pack as well as those of the first two service packs.

The version number of the latest service pack installed on a computer can be retrieved using the Win32_OperatingSystem class. The Win32_OperatingSystem class cannot retrieve the version number of previously installed service packs. However, because all the fixes and functionality found in previous service packs are included in the latest service pack, you will be able to determine the actual code base of the operating system. The code base consists of the operating system (for example, Windows 2000 Professional 5.0.2195) plus any service packs that have been used to upgrade that operating system.

Note

Two service pack related properties are available through the Win32_OperatingSystem class. These two properties are shown in Table 8.10.

Table 8.10   Win32_OperatingSystem Service Pack Properties

PropertyDescription
ServicePackMajorVersionMajor version of the latest service pack installed on the computer.

If the latest service pack is 4 or 4a, the major version is 4. If no service pack has been installed, this value is 0.

ServicePackMinorVersionMinor version of the latest service pack installed on the computer.

If the latest service pack is 4a, the minor version is a. If the latest service pack is 4, there is no minor version. To ensure that you identify the proper service pack, you must check both the major version and the minor version.

Scripting Steps

Listing 8.8 contains a script that identifies the latest service pack 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 the operating system currently in use on the computer.

  4. Echo the values of the service pack major version and the service pack minor version.

Listing 8.8   Identifying the Latest Installed Service Pack

1 2 3 4 5 6 7 8 9

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.ServicePackMajorVersion _ & "." & objOperatingSystem.ServicePackMinorVersion Next


 Send us your feedback « Previous | Next »   

Категории