Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I require user to uninstall previous version with NSIS

I have just started using NSIS.
It works very well but I find the documentation a bit unstructured. How do I require user to uninstall previous version before installing a new version with NSIS?

NSIS (Nullsoft Scriptable Install System) is an open source system to create Windows installers.

like image 825
Nifle Avatar asked Apr 05 '09 20:04

Nifle


People also ask

What is Nsis uninstall information?

NSIS is a tool used to create installers/uninstallers but some malware has also used the name to try to seem legitimate. "NSIS Uninstall Information" is not a folder that most NSIS installers will create but that does not mean that it is impossible for a genuine software installation to use this directory.

How do you compile NSIS?

nsi file by simply right-clicking on it in Explorer and selecting 'compile'. If you want to use MakeNSIS on the command line, the syntax of makensis is: makensis [ option | script.

What is a NSIS script?

Nullsoft Scriptable Install System (NSIS) is a script-driven installer authoring tool for Microsoft Windows backed by Nullsoft, the creators of Winamp. NSIS is released under a combination of free software licenses, primarily the zlib license.


2 Answers

Another approach is to make a UninstallPrevious hidden section and make it run before all other sections in the installer. I also suggest making the uninstaller run silently.

; The "" makes the section hidden.
Section "" SecUninstallPrevious

    Call UninstallPrevious

SectionEnd

Function UninstallPrevious

    ; Check for uninstaller.
    ReadRegStr $R0 HKLM "${HKLM_REG_KEY}" "InstallDir"

    ${If} $R0 == ""        
        Goto Done
    ${EndIf}

    DetailPrint "Removing previous installation."    

    ; Run the uninstaller silently.
    ExecWait '"$R0\Uninstall.exe /S"'

    Done:

FunctionEnd

The advantage of this approach is that the user won't uninstall the old version until they're ready to install the new version. Furthermore, they don't even have to make a decision about uninstalling the old version, it just magically disappears.

Of course, depending on your needs, you may want the user to confirm uninstalling, in which case use the spinner_den's approach.

like image 150
cdmckay Avatar answered Oct 26 '22 23:10

cdmckay


NSIS is a great Windows Installer. Here is how I use NSIS to uninstall the current version while installing a new version of the same application. Add the following function to your NSIS script.

Function .onInit

         Exec $INSTDIR\uninst.exe 

FunctionEnd

Also you can check out this link on the NSIS wiki on "Auto-uninstall old before installing new".

like image 31
spinner_den_g Avatar answered Oct 26 '22 22:10

spinner_den_g