Skip to content
⌘ NSIS Forum Archive

Creating an uninstaller at compile-time

4 posts

cgytrus#

Creating an uninstaller at compile-time

We have an auto-update system separate from the NSIS installer in our project but we use NSIS for uninstalling the app.
If the installer changes in an update and the app auto-updates, the uninstaller won't get updated, potentially causing issues when a user wants to uninstall the app.

Is it possible to generate the uninstaller in compile-time using the makensis command so that it can be packaged together with the auto-update package and updated with the app during an auto-update without having to make the auto-update system rely on using the installer to update the app?
Anders#
Slightly over-complicated because it executes it for you as well:

Function .onInit
!ifdef GENERATEUNINSTALLER
WriteUninstaller "${__FILEDIR__}\Uninstaller.exe"
SetErrorLevel 0
Quit
!if "${GENERATEUNINSTALLER}" <> 42
!tempfile TMPINST
!delfile "${TMPINST}"
!makensis '-DGENERATEUNINSTALLER=42 "${__FILE__}" "-XOutFile `${TMPINST}.exe`"' ; Create the installer that just uses WriteUninstaller
!system '"${TMPINST}.exe" /S' ; Run it so WriteUninstaller gets called
!delfile "${TMPINST}.exe"
!error 'Finished generating uninstaller...aborting now'
!endif
!endif
FunctionEnd
Section
SetOutPath $InstDir
WriteUninstaller "$InstDir\Uninstaller.exe"
# ...
SectionEnd
Section -un.Uninstall
# ...
Delete "$InstDir\Uninstaller.exe"
RMDir "$InstDir"
SectionEnd 
makensis.exe -DGENERATEUNINSTALLER "mysetup.nsi"
JasonFriday13#
If using 3.08 or newer, you can use !uninstfinalize to copy the uninstaller to the script dir and rename it too.