Login to participate
Endpoint Management & Virtualization ArticlesRSS

Uninstalling Changes Done by a WiseScript

Deepanshu's picture

You can use the Run WiseScript custom actions to make changes to the destination computer when the script is run from your .MSI.

Example: You can use the Install File(s) script action to add files or you can use the Edit Registry script action to add, edit, or delete keys or values in the registry.

However, the Windows Installer installation does not recognize any changes the WiseScript makes to the system and therefore will not uninstall any of these changes during uninstall of the main Windows Installer installation.

To solve this problem, do the following:

  1. In the WiseScript, include steps to install an installation log and Unwise32.exe.
  2. In the .MSI, during an uninstall, use a custom action to call the Unwise32.exe that is
  3. in the WiseScript.

Example: You have an .MSI named Core and a WiseScript named CorePlus. CorePlus includes an Install File(s) script action that installs a file named A.dll. You want to make sure that A.dll gets uninstalled when Core is uninstalled.

In the Core .MSI, do the following:

  1. Select MSI Script and click the Execute Immediate tab.
  2. Scroll down and click directly below the RemoveExistingProducts action.
  3. Add an If Statement with a value of NOT Installed.

    This condition causes it to run only during initial installation of Core.

  4. Add a Run WiseScript From Installation custom action and set:
    1. Custom Action Name to ActionInstallCorePlus
    2. WiseScript .EXE File to C:\Plus\CorePlus.EXE

      Leave Command Line blank. On the Properties tab, leave the defaults.

  5. Add an End Statement.

    The above script lines install CorePlus, which in this example is A.dll. In the following script lines, you make provisions for the uninstall.

  6. Add an If Statement with a value of REMOVE~="ALL".

    This condition causes it to only run during uninstall of Core.

  7. Add an Execute Program From Destination custom action and set:
    1. Custom Action Name to RemoveCorePlus
    2. Working Directory to INSTALLDIR
    3. EXE and Command Line to [INSTALLDIR]Unwise32.exe /S install.log

      On the Properties tab, leave the defaults.

  8. Add an End Statement.

The MSI script looks like this (the script lines are numbered for clarity):

  1. If NOT Installed then
  2. Run WiseScript From Installation C:\Plus\CorePlus.EXE
  3. End
  4. If REMOVE~="ALL" then
  5. Execute Program From Destination [INSTALLDIR]unwise32.exe /S install.log Default Directory Program Files\Core
  6. End

In the CorePlus WiseScript, do the following:

  1. Add a Get Windows Installer Property script action and set
    1. Dest. Variable to MAINDIR
    2. Property Name to INSTALLDIR

      INSTALLDIR is the installation directory of Core, the main Windows Installer installation. This sets the WiseScript installation directory to the same value as the main installation's installation directory.

  2. Add a Set Variable script action and set:
    1. Variable to MAINDIR
    2. New Value to %MAINDIR%
    3. Operation to Remove trailing backslashes.

      INSTALLDIR has a trailing backslash, but to be compatible with WiseScript, MAINDIR cannot have a trailing backslash.

  3. Add an Open/Close INSTALL.LOG script action with Open new installation log marked and the log file path specified as %MAINDIR%\install.log. This causes the WiseScript to create a log in the installation directory.
  4. Add an Install File(s) script action and set:
    1. Source Pathname for Unwise32.exe
    2. Destination Pathname to %MAINDIR%\Unwise32.exe.

      Unwise32.exe is located within the WiseScript Express directory under the Wise for Windows Installer directory.

  5. Add an Install File(s) script action and set:
    1. Source Pathname for A.dll
    2. Destination Pathname to %MAINDIR%\A.dll.

      Add any other necessary script actions. (Example: You could edit registry entries, check if a certain file or directory exists, or rename a file or directory.) For this example, the CorePlus script installs only A.dll. For troubleshooting purposes, you might also want to add a Display Message script action that shows the value of %MAINDIR%. This lets you know when the WiseScript runs, and also gives you debugging abilities.

The sample WiseScript looks like this (the script lines are numbered for clarity):

  1. Get Windows Installer Property INSTALLDIR into MAINDIR
  2. Set Variable MAINDIR to %MAINDIR%
  3. Open new installation log file %MAINDIR%\install.log
  4. Install File C:\Program Files\Unwise32.exe to %MAINDIR%\Unwise32.exe
  5. Install File C:\Plus\A.dll to %MAINDIR%\A.dll

Cheers
Deepanshu