Uninstall Product action

The Uninstall Program action checks for the presence of a registered uninstaller for any program, and optionally runs the uninstaller or fails the installation. You can use this action to uninstall the previous version of your product or related products, or to detect the presence of a conflicting product and prevent installation of your product.

Uninstaller detection searches the Software\Microsoft\Windows\CurrentVersion\Uninstall registry keys under HKEY_LOCAL_MACHINE and HKEY_CURRENT_USER, in that order. If the desired installer is found and must be executed, InstallMate first tries to use the QuietUninstallString command line; if that is not defined, it will use UninstallString instead.

Note: From version 9.42.0 onward, InstallMate will automatically generate the appropriate uninstallation command line for MSI-based installers if both the QuietUninstallString and the UninstallString commands are missing or empty for the given uninstall key. In that case, a diagnostic message TSU:A0069 will be logged in the installation log file.

Exit codes

For synchronous actions (see Time out below), the installer stores the uninstaller's exit code in the LastExitCode variable; you can use this variable in the conditions of subsequent actions. The exit code is one of the following:

  1. If the uninstaller is not present, LastExitCode is set to 0 (zero).
  2. Else if the uninstaller is present but cannot be executed (see Uninstall type below), LastExitCode is set to 1638 (ERROR_PRODUCT_VERSION).
  3. Else if an error occurs when the uninstaller is started, LastExitCode is set to the (nonzero) Windows error code.
  4. Else if the action terminates prematurely due to a time-out, LastExitCode is set to 259 (STILL_ACTIVE).
  5. Else if a secondary process is specified (see Process 2 below), its exit code is stored.
  6. Else the exit code of the uninstaller itself is stored.

For asynchronous actions, LastExitCode is set to 0 if the uninstaller was started successfully, or to a nonzero Windows error code if an error occurred while starting the program.

Note: LastExitCode is overwritten by the next action that runs an external program (including Run Script, Run DLL, Run Program, and Uninstall Product).

Attributes

The following attributes and options are available.

Attribute Description
Action name Enter the name of the action. This name is only used in InstallMate and is not visible to the user.
Uninstall type

Select the uninstallation type from the drop-down list. The following choices are available:

Uninstall type Description
Fail if present Fail the installation if the uninstaller is present on the target system. You can use this option to prevent installation if an incompatible product is present on the target system.
Uninstall if possible, else fail Run the uninstaller if present and able to run at the installer's TsuQuiet level. If the uninstaller is present but cannot be run at the current TsuQuiet level, fail the installation.
Uninstall if possible, else ignore Run the uninstaller if present and able to run at the installer's TsuQuiet level. If the uninstaller is present but cannot be run at the installer's TsuQuiet level, continue without uninstalling (which might overwrite the other product or previous version).

Uninstallation behavior differs depending on the installer's TsuQuiet level:

  • If the installer is not running in silent mode (/q0 or no /q command line option at all; TsuQuiet = 0), then any uninstaller may run because the user will be able to provide any feedback that the uninstaller may require (such as clicking Yes to confirm uninstallation).
  • If the running is running in silent mode (/q or /q2 command line option; TsuQuiet > 0), then only uninstallers that have a QuietUninstallString, have additional Arguments (see below), or are InstallMate or Windows Installer uninstallers, may run, because they can be run without user interaction.
Uninstall key

Enter the uninstaller registry key name for the product that must be uninstalled. This is the registry key under Software\Microsoft\Windows\CurrentVersion\Uninstall that contains the uninstallation information for the product that you want to uninstall.

Tip: To uninstall a previous version of the current product, enter <ProductCode> in this field.

Arguments

Enter additional arguments for the uninstaller, if any. Be sure to enclose any arguments that contain (or might expand to contain) spaces in quotes, for example "argument with spaces" or "<INSTALLDIR>".

Any arguments that you enter in this field are added to the existing uninstaller arguments taken from QuietUninstallString or UninstallString. This field is meant in particular to provide the correct arguments for a quiet uninstallation; in fact, if you provide any arguments in this field, InstallMate assumes that the uninstaller will be able to run in silent mode (see Uninstall type above).

Tip: You do not have to specify additional "silent mode" arguments for the following uninstallers:

  • Any uninstaller that has a QuietUninstallString command line;
  • Any InstallMate uninstaller, including Tarma ExpertInstall 3.x and Tarma Installer 5.x uninstaller;
  • Any MSI-based uninstaller.
Query uninstall

Check this box to ask the user for permission before uninstalling the product; clear it to perform the uninstallation without confirmation. This option is ignored if the installer is running in silent mode (/q command line option; TsuQuiet > 0).

If checked, the installer will display Message #00268 as the confirmation prompt. If the user declines the uninstallation, the installation fails.

Execute

Select the action's execution mode from the drop-down list. The following choices are available:

Execute Description
Immediate Execute the action when encountered in the action sequence. This is the default.
Commit Defer execution until the installation is committed. This option allows you to implement the "Commit" part of a two-phase commit protocol that is only executed if the installation was successful.
Rollback Defer execution until the installation is rolled back. This option allows you to implement the "Rollback" part of a two-phase commit protocol that is only executed if the installation fails and must be rolled back.
Not in silent mode Check this box to skip the action if the installer is running in silent mode (/q command line option; TsuQuiet > 0); clear it to run the action in all modes.
Show

Select the desired visibility of the uninstaller from the drop-down list. The following choices are available:

Show Description
Normal Show the uninstaller normally.
Minimized Show the uninstaller minimized (only on the taskbar).
Maximized Show the uninstaller maximized.
Hidden Hide the uninstaller. Use this option with caution; if the uninstaller requires user input, then the user will not be able to provide it and the uninstaller will hang until it is terminated by the user or the system.

Note: If the uninstaller runs in silent mode, this option may or may not have effect, depending on the uninstaller's implementation.

Hide installer while
uninstaller runs

Check this box to hide the installer's main window while the action runs; clear the box to keep the installer's window visible.

Note: This option only has effect if the action runs synchronously, i.e., with the Time out option selected. During asynchronous actions, the installer remains visible.

Time out

Check this box and enter the time-out period in seconds to execute the action synchronously; clear it to execute the action asynchronously. If the action is executed synchronously, the installer will wait for it to complete; for an asynchronous action, the installer starts the action and then immediately continues.

Note: If the time-out period expires before the uninstaller terminates, the installer continues with its next action. However, the uninstaller itself is not terminated; it will remain active in the background until it terminates of itself or is forcefully terminated by the user or the system.

Process 2 Enter the name of a secondary process to wait for, or leave empty to wait only for the uninstaller process. This option only has effect if Time out is checked. It is useful if the uninstaller starts a secondary program that must complete before the installer continues.
Exit code

Select the exit code handling from the drop-down list. The following choices are available:

Exit code Description
Ignore Ignore the uninstaller's exit code.
Fail if nonzero Terminate the parent action sequence and the fail the installation if the uninstaller's exit code is nonzero.
Fail if zero Terminate the parent action sequence and the fail the installation if the uninstaller's exit code is zero. This option is not recommended, because the exit code may be zero if the uninstaller runs asynchronously and is started successfully.

The effectiveness of this option depends on the way the uninstaller is programmed. It is customary that successful completion of a program is indicated by an exit code of zero, and failure by a nonzero exit code. (This is how InstallMate uninstallers behave, for example.) However, not all programs comply with this convention. Furthermore, the Uninstall Product action itself may set a nonzero exit code if it cannot start the uninstaller or if the time-out period expires before the uninstaller terminates (see Exit codes).

Before you use the Exit code option, we recommend that you convince yourself that the uninstaller in question returns an appropriate exit code. If you want to use the uninstaller's exit code to terminate the installation or control the execution of subsequent actions, we suggest that you set the Exit code option to Ignore and use one of the following alternative approaches:

  • To terminate the installation if the uninstaller returns a nonzero exit code, insert a MessageBox action immediately after the current Uninstall Product action. Set the MessageBox action's Condition to LastExitCode <> 0 and set its Fail mode to Fail if run. Enter an appropriate error message in its Message field.
  • To execute or skip any subsequent actions depending on the uninstaller's exit code, use the conditional expressions LastExitCode = 0 or LastExitCode <> 0, respectively, in the subsequent actions. Please note that the LastExitCode variable will be overwritten by the next Run Script, Run Program, or Uninstall Product action.
CPU Select the Windows architectures on which the action must be executed. This CPU selection acts as an additional condition for the action.
Condition

Enter the conditional expression that determines if the action will be executed, or leave empty for unconditional execution.

Important: If you use the Uninstall Product action to uninstall a previous version of the current product, then you should set Condition to NOT Installed. This ensures that the uninstallation only takes place during the first installation of the new version and not each time the installer runs for a "Change" or "Repair" installation.

Disabled Check this box to disable the action. A disabled action is not included in the installer and not checked during the build. You can use this option to remove actions temporarily from your installer without permanently deleting them. Disabled actions are shown with a grayed-out icon.

Related topics

Actions, Working with attribute panes