nsis

NSIS uninstall previous app before proceeding with installation


Before proceeding with installation I would like to give the user the option of uninstalling the app, if it has previously been installed. Here is my attempt below:

 Function .onInit
    ; $R0 contains the path to the uninstaller
    IfFileExists $R0 +1 NoPriorInstall
        MessageBox MB_YESNO "Existing App installation found. Installation cannot proceed unless App is uninstalled.$\r$\nUninstall App?" IDYES UninstallApp
            Abort
 UninstallApp:
        ExecWait $R0
 NoPriorInstall: 
 FunctionEnd

It works however the non-modal "Permanently remove App" YESNO dialog pops up at the same time as the non-modal "App Setup" wizard so that its possible to install the app before uninstalling it or the other way round.

I'd like to either have:

I hoped running the uninstaller R0 I would like to run the app uninstaller if one exists, i.e. if the app is already before


Solution

  • You need invoke the old uninstaller with the special _?= parameter if you want to wait on it. If you do this, you have to delete the uninstaller yourself after it has finished.

    You can find my full example of this on the wiki.