Upgrading Software

Microsoft® Windows® 2000 Scripting Guide

As new versions of a software package are released, you might need to upgrade existing copies of that software. These upgrades can be carried out using the Win32_Product Upgrade method.

The Upgrade method works only under the following conditions:

  • It is used only with a software upgrade package.

    Upgrade packages are .msi files specifically designed to upgrade a previous version of the software. If you attempt to use a standard Windows Installer package with the Upgrade method, you will receive an error message 1636:

    This patch package could not be opened.
    Contact the application vendor to verify that this is a valid Windows Installer patch package.
    
  • A previous version of the product is already installed.

    The Upgrade method will fail if a previous version of the software is not found. For example, to upgrade a computer from version 1 to version 2 of an application, version 1 must first be installed on that computer. If it is not, the upgrade will fail, and version 2 will not be installed.

In turn, the Upgrade method requires two parameters:

  • PackageLocation. Path to the Windows Installer upgrade package, relative to the computer on which the software is being installed. The path can be referenced using UNC paths or mapped network drives.

  • Options. Command-line options required for installing the software. If no options are required, this parameter should be left blank.

Scripting Steps

Listing 8.16 contains a script that upgrades an application called Personnel Database 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_Product class.

    Because the upgrade is targeted toward a particular piece of software, include a WHERE clause to limit data retrieval to installed applications with the name Personnel Database. Without this clause, the Upgrade method would be applied (unsuccessfully) to each application installed on the computer.

  4. For each instance of Personnel Database in the collection, call the Upgrade method, specifying the path to the Installer file. This path must be relative to the computer on which the upgrade will take place.

    Note

    • If you are upgrading software on a remote computer and the Installer file is located on a third computer, you need to reference the UNC path to the file and use delegation to allow the computer being upgraded to connect over the network and retrieve that file. For information about using delegation, see "Installing Software on a Remote Computer" earlier in this chapter.

Listing 8.16 Upgrading Software

  
1
2
3
4
5
6
7
8
strComputer = "."
Set objWMIService = GetObject("winmgmts:" _
 & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")
Set colSoftware = objWMIService.ExecQuery _
 ("SELECT * FROM Win32__Product WHERE Name = 'Personnel Database'")
For Each objSoftware in colSoftware
 errReturn = objSoftware.Upgrade("c:\scripts\database2.msi")
Next