Uninstalling an MSI file using a WMI Query

Last modified by Sabrina V. on 2025/03/04 07:13

Initial situation

In this Client Command, the WMI Query is used to determine the MSI IdentifyingNumber, which is then used in the Uninstall MSI package Command. By using the WMI Query, you can also work with wildcards to take into account several software versions. In this example, the software 7-Zip is to be uninstalled. The data compression program is often not on a uniform level in the company, which would make a tedious search for the individual product codes necessary. Avoid the individual uninstallations of different versions and thus ensure a uniform software level.

Hinweis  Note:  

 This is only one way of uninstalling an MSI file using a Client Command. If, for example, you only want to install one version of a software, you can also do this using the product code and ignoring errors (using error codes). You can find out how to do this here.

Otherwise, proceed as follows:

Select Script

  1. Navigate to the Client Commands > Create module.
  2. Click on Add in the ribbon bar. The Client Command Editor will open, where you need to decide whether it is a Console or Client Script. In this case, select the Cient Script.

Select and edit the WMI Request Command

Warning  Warning:  

Within the WMI query you will access the Win32_Product WMI class. This class represents the products as they are installed by Windows Installer or as they are stored as installation packages on clients. This can result in a large number of entries in the event log as all MSI installation files are listed. Please be aware that this step can cause delays. Microsoft describes this issue as follows:

Win32_Product is not query optimized. Queries such as "select * from Win32_Product where (name like 'Sniffer%')" require WMI to use the MSI provider to enumerate all of the installed products and then parse the full list sequentially to handle the “where” clause. This process also initiates a consistency check of packages installed, verifying and repairing the install. With an account with only user privileges, as the user account may not have access to quite a few locations, may cause delay in application launch and an event 11708 stating an installation failure.

  1. First select the WMI > WMI Query Command from the Command list.
  2. Double-click to open the Command. The launch window will show the details of the WMI settings.
  3. Select Simple mode.
  4. Select „root\cimv2“ from the drop down list under 'Root'.
  5. Click the WMI icon next to the WMI class. In the window that opens, locate 'Win32_Product' or enter it manually in the search box. Further down the right hand side you will see more information about each entry. Click OK.
  6. In the text box, type „CAPTION like "7-Zip%"“.
  7. Save the results to a variable. To do this, click the icon next to the variable name.
  8. In the window that opens, add a new variable under Actions. To do this, type 'WMIRESULT' in the variable name box and click the plus sign.
1736511066054-639.png

Inserting the WMIRESULT variable

      9. Exit this step by clicking OK and return to the original window. Close this window by clicking OK again.

65_Use Case Client Commands_WMI Abfrage_Details_539.png

WMI Query

Select and edit the Uninstall MSI package Command

  1. Load the Uninstall MSI package (MSI) Command into the Script by selecting it with a double click. Indent the Command either via the quick selection bar or the shortcut CTRL + right arrow key so that it is displayed below the first Command (WMI Query).

    Hinweis  Note:  

    If you have multiple installations of the same software in your environment (in this example, 7-Zip), you can also use the indentation to find multiple items. The Command is executed multiple times because it is a loop Command and the software you are looking for is uninstalled until no more matching IDs are found.

  2. Enter the product code %WMIRESULT.IdentifyingNumber% in the Details tab for the product information. The variable is made up of the variable value that you previously saved (WMIRESULT) and the IdentifyingNumber. The IdentifyingNumber is the product ID that is needed to uninstall all software entries for 7-Zip.
  3. Select Unattended as the display mode.
  4. Under Options, tick the box next to Suppress Restart. If a restart is necessary for the uninstallation, it will not be carried out immediately afterwards. This means that other open programs or files will not simply be closed without you saving them.
  5. Click OK.
65_Use Case Client Commands_MSI Paket deinstallieren_WMI Result_504.png

Uninstalling MSI packages

The last step is to save your Client Command in the editor.

65_Use Case Client Commands_WMI Abfrage Gesamtübersicht_1436.png

Client Command Editor: Uninstalling an MSI file using a WMI query

On execution of the Client Command, the software 7-Zip is uninstalled from the Clients.

© Aagon GmbH 2025
Besuchen Sie unsere neue Aagon-Community