Question

I am developing an installer for my application, using NSIS installer script, and the problem that I am facing is that if I am installing the same application, in different folders, and if I am using the uninstall.exe from the folder where I have installed first, it will install the last installed, actually both uninstall.exe will point to the location of the last installed.

This is how I am making the uninstall keys:

' ; Write the uninstall keys for Windows
WriteRegStr HKLM Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANY}${APPNAME}" "DisplayName" "${APPNAME} (Remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANY} ${APPNAME}" "UninstallString" '"$INSTDIR\uninstall.exe"''

And the desired behaviour is that each "uninstall.exe" should point to the installation folder where it belongs. I know there is alread a similar question, but there is nothing helpful for me. (nsis uninstall problem) Any help/idea will be highly appreciated.

Was it helpful?

Solution

If you want to allow multiple installs each install would have to use a unique uninstall key name:

...
Page Directory
Page InstFiles

!include LogicLib.nsh

Section
SetOutPath $InstDir
System::Call 'OLE32::CoCreateGuid(g.r1)' ; Generate a new GUID for this install
WriteUninstaller "$InstDir\Uninst.exe"
FileOpen $0 "$InstDir\Uninst.exe" a
${If} $0 <> 0
    FileSeek $0 0 END
    FileWrite $0 $1 ; Save the GUID in the uninstaller
    FileClose $0
${EndIf}
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_$1" "DisplayName" "${APPNAME} (Remove only)"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_$1" "UninstallString" '"$InstDir\Uninst.exe"'
File "MyApp.exe"
SectionEnd

Section Uninstall
FileOpen $0 "$ExePath" r
${If} $0 <> 0
    FileSeek $0 -38 END
    FileRead $0 $1 38
    FileClose $0
    ${If} $1 != ""
        DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\MyApp_$1"
    ${EndIf}
${EndIf}
Delete "$InstDir\Uninst.exe"
Delete "$InstDir\MyApp.exe"
RMDir $InstDir
SectionEnd
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top