Export (0) Print
Expand All
0 out of 1 rated this helpful - Rate this topic

Identifying the Latest Installed Service Pack

Microsoft® Windows® 2000 Scripting Guide

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:

  • Many hot fixes or software updates cannot be installed unless a particular service pack has previously been installed on a computer.

    Hot fixes (code fixes released to address specific problems in the operating system) are generally tied to a service pack, meaning the service pack must be installed before the hot fix can be applied. Before you can apply hot fixes or other software updates, you might need to know whether a particular service pack has been installed on a computer.

  • Technical support personnel (including those from Microsoft Product Support Service) need to know which service packs have been installed when troubleshooting problems.

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

  • If it is important for auditing purposes to know whether previous service packs were installed, you can use WMI to query the System Event Log for all instances of event 4359. An event with this event code is written to the System Event Log each time a service pack or hot fix is installed.

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

Property

Description

ServicePackMajorVersion

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

ServicePackMinorVersion

Minor 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

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.