Removing Software

Microsoft® Windows® 2000 Scripting Guide

Software installation is rarely permanent; instead, software is typically removed at some point in time, and for any number of reasons:

  • The functionality supplied by the software is no longer needed.

  • The software is being replaced by a competing software package.

  • The software is installed on the wrong computer.

  • The software is not licensed for use in the organization.

The Win32_Product Uninstall method can be used to remove software from a computer. The Uninstall method can be used either on the local computer or on a remote computer, and without delegation. This is because no multihop security operations are involved. Instead, the software is simply removed from the computer.

Although the Uninstall method can remove software from a computer, it does not override Group Policy. For example, if Microsoft Excel has been installed on a computer, you can use the Uninstall method to remove it. However, if Microsoft Excel is available to the user through Group Policy, the user will be able to reinstall the application.

Scripting Steps

Listing 8.17 contains a script that deletes software 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 only one software package is to be deleted, include a WHERE clause to limit data retrieval to installed applications with the name Personnel Database. Otherwise, the script would remove all the software installed on the computer.

  4. For each instance of Personnel Database in the collection, call the Uninstall method to remove the software.

Listing 8.17 Removing Software


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