Windows Installer, Java Installer, Freeware Installer
Home|Contact|Site Map|TOC|Search
Download  Features   Java  Licensing  Purchase  Testimonials  Support  Forums

How do I uninstall another MSI package when my application is uninstalled?

Answer

WarningThis is not recommended because it will make your installation package remove other applications.

If your installation package includes some MSI-based prerequisites you may want to remove them when your application is uninstalled. For this you can use a custom action:

  • go to the Custom Actions page
  • show the "InstallExecuteSequence" -> "InstallFinalize" standard action (you can use the "Show standard action" button on the toolbar)
  • under "InstallFinalize" create a new "Exe with working dir" custom action
  • set the "Working Dir" field to SystemFolder
  • set the "Command Line" field to [SystemFolder]msiexec.exe /x GUID /qb, where GUID is the Product Code of the package you want to uninstall
  • in the "Execution Properties" section set the "Asynchronous Execution, do not wait for return" option
  • in the "Expression" field of the "Execution Condition" section set this condition: REMOVE="ALL"

NoteThe custom action is launched asynchronously because two MSI-based installations cannot run at the same time. This way the custom action runs right after the main install process is finished.

NoteIf the product you want to remove is not MSI-based, you can use a "Launch file or open URL" custom action to launch the Uninstaller of the product (if it has one).

Since we don't want to uninstall applications on the target machine without the user's permission, you can use a custom action which prompts the user. The custom action can look like this:

      Function Ask
	      MsiMsgBox("Do you want to uninstall the prerequisites?")	
      End Function
      
      Function MsiMsgBox(msg)
	      Const msiMessageTypeUser = &H03000000
	      Const msiMessageStatusYes = 6
	      Set record = Session.Installer.CreateRecord(1)
	      record.StringData(0) = "[1]"
	      record.StringData(1) = CStr(msg)
	      ans=Session.Message(msiMessageTypeUser + vbYesNo, record)
	      If ans=msiMessageStatusYes Then
		        Session.Property("UNINSTALL_PREREQ")="YES"
	      Else
		        Session.Property("UNINSTALL_PREREQ")="NO"
	      End If
      End Function
      

This VBScript custom action shows a message box which asks the user about uninstalling the prerequisites. Also, it sets the UNINSTALL_PREREQ property to the answer given by the user. You can schedule this custom action under the "InstallExecuteSequence" -> "InstallFinalize" standard action as Immediate. Also, the condition of the custom action should now be:

REMOVE="ALL" AND UNINSTALL_PREREQ="YES"
Privacy Policy | Windows Installer | Search Engine Ranking | Link Analyzer