Installing Software on the Local Computer

Microsoft® Windows® 2000 Scripting Guide

The ability to install software without using Group Policy can be an enormous boon to administrators; this allows you to install software without requiring user interaction and without requiring the user to log off and log on or the computer to restart. In addition, a WMI script can help ensure a successful installation by doing such things as checking for available memory or available disk space before beginning the installation process. If there is not enough memory or disk space on the target computer, your script can terminate without installing the software. This prevents any problems that can occur from attempting to install software on computers not capable of running that software.

The Win32_Product class includes an Install method that can be used to install software on the local computer. (In other words, the script physically resides on the computer where the software will be installed.) Software can also be installed on remote computers; however, because remote installation might require some additional configuration, the remote installation process is discussed in the next section of this chapter.

Regardless of whether the software is installed locally or remotely, the Install method requires three parameters:

  • PackageLocation. Path to the Installer package, which is relative to the computer on which the software is being installed and which can be referenced using a Universal Naming Convention (UNC) path.

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

  • AllUsers. Boolean value that indicates whether the software should be available to all the users on a computer or just the currently logged-on user.

    • If set to True, the software will be installed under the All Users profile.

    • If set to False, the software will be installed under the profile of the user whose credentials are being used to run the script. For example, if the script is running under the Administrator account, the software will be installed under the Administrator profile and thus will not be accessible to other users.

Scripting Steps

Listing 8.14 contains a script that installs software for all users on a computer. To carry out this task, the script must perform the following steps:

  1. Create a constant ALL_USERS and assign it the value True. This constant is used to install the software in the All Users profile.

  2. Use a GetObject call to connect to the WMI service.

  3. Retrieve an instance of the Win32_Product class.

  4. Use the Install method to install the Windows Installer package. This method requires the following three parameters:

    • C:\Scripts\Database.msi - The location of the software package being installed

    • Null - Indicates that no command-line options are required to install the product

    • ALL_USERS - Constant (with the value True) that installs the software under the All Users profile

Listing 8.14 Installing Software

  
1
2
3
4
Const ALL_USERS = True
Set objService = GetObject("winmgmts:")
Set objSoftware = objService.Get("Win32_Product")
errReturn = objSoftware.Install("c:\scripts\database.msi", , ALL_USERS)