Uninstalling a previous MSI

From NSIS Wiki
Jump to navigationJump to search
Author: anonymous (talk, contrib)


Description

I migrated my software from an MSI installer to NSIS. Upon installing the new version of my software, I first needed to uninstall the previous MSI package. Here's how I did it:

The Script

Function UninstallMSI
  ; $R0 should contain the GUID of the application
  push $R1
  ReadRegStr $R1 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\$R0" "UninstallString"
  StrCmp $R1 "" UninstallMSI_nomsi
    MessageBox MB_YESNOCANCEL|MB_ICONQUESTION  "A previous version of ${MUI_PRODUCT} was found. It is recommended that you uninstall it first.$\n$\n\Do you want to do that now?" IDNO UninstallMSI_nomsi IDYES UninstallMSI_yesmsi
      Abort
UninstallMSI_yesmsi:
    ExecWait '"msiexec.exe" /x $R0'
    MessageBox MB_OK|MB_ICONINFORMATION "Click OK to continue upgrading your version of ${MUI_PRODUCT}"
UninstallMSI_nomsi: 
  pop $R1
FunctionEnd

From the main Section I then do the following:

push $R0
  StrCpy $R0 "{48E5A72D-whatever-xxxx}";  the MSI's ProductID of my package
  Call UninstallMSI
pop $R0

In my case I had to do this for every ProductID for each previous version of my application. Joost N.

Information for InstallShield users

Whilst migrating from an InstallShield product to NSIS, I found that the uninstall string is stored in a 'unique' fashion. The Registry entry looked like this:-

HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\InstallShield_{GUID}

See also Removing MSI packages with MSI related functions