I am attempting to debug the NSIS installer for QGIS (which is not removing registry entries upon uninstall). I've created a simple test installer to speed up the process. My test installer is not writing registry entries. I can't see what I'm missing.
When run, I see the first message "Updating Registry" but I do not see the message for an error.
I am running on Windows 8.1 Pro.
!include "MUI.nsh"
;NSIS Includes
!include "x64.nsh"
!include "LogicLib.nsh"
;----------------------------------------------------------------------------------------------------------------------------
;Installer Pages
!define MUI_WELCOMEPAGE_TITLE_3LINES
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_INSTFILES
!define MUI_FINISHPAGE_TITLE_3LINES
!insertmacro MUI_PAGE_FINISH
;----------------------------------------------------------------------------------------------------------------------------
; Language files
!insertmacro MUI_LANGUAGE "English"
;----------------------------------------------------------------------------------------------------------------------------
RequestExecutionLevel admin
# define the file name "gupsdata_setup.exe"
Outfile "setup_gupsdata.exe"
# define the installation directory
InstallDir $PROGRAMFILES64\_gups_test
# create read/write test folders
Function .onInit
CreateDirectory $INSTDIR\read_write\write_me_1
CreateDirectory $INSTDIR\read_write\write_me_2
CreateDirectory $INSTDIR\read_only\read_me
# Make the directory "$INSTDIR\read_write" read write accessible by all users
AccessControl::GrantOnFile \
"$INSTDIR\read_write" "(BU)" "GenericRead + GenericWrite"
FunctionEnd
# GUPS Data
Section "GUPS DATA" SecGUPSDATA
# define the output path for this file
SetOutPath $PROFILE\GUPSGIS\gupsdata
# define what to install and place it in the output path
File .\gupsdata\gupsdata.db
SectionEnd
Section "Registry Update" SecRegUp
WriteUninstaller "$INSTDIR\Uninstall.exe"
MessageBox MB_OK "Updating Registry"
;Registry Key Entries
;HKEY_LOCAL_MACHINE Install entries
;Set the Name, Version and Revision of QGIS+ PublisherInfo + InstallPath
WriteRegStr HKLM "Software\GUPSTEST" "Name" "GUPSTEST"
WriteRegStr HKLM "Software\GUPSTEST" "VersionNumber" "1"
WriteRegStr HKLM "Software\GUPSTEST" "VersionName" "TestMe"
WriteRegStr HKLM "Software\GUPSTEST" "VersionInt" "101011"
WriteRegStr HKLM "Software\GUPSTEST" "BinaryRevision" "11"
WriteRegStr HKLM "Software\GUPSTEST" "Publisher" "Me"
WriteRegStr HKLM "Software\GUPSTEST" "WebSite" "http://web.com"
WriteRegStr HKLM "Software\GUPSTEST" "InstallPath" "$INSTDIR"
;HKEY_LOCAL_MACHINE Uninstall entries
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "DisplayName" "GUPS Test Display name"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "UninstallString" "$INSTDIR\Uninstall.exe"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "DisplayIcon" "$INSTDIR\icons\QGIS.ico"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "EstimatedSize" 1
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "HelpLink" "http://wiki.com"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "URLInfoAbout" "http://wiki.com"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST" "Publisher" "Me"
IfErrors 0 +2
MessageBox MB_OK "Error writing registry entries"
SectionEnd
Section /O "Text File" SecTEXTFILE
SetOutPath $PROFILE\GUPSGIS\gupsdata
File .\gupsdata\test.txt
Var /GLOBAL GUPS_DATA_DIR
StrCpy $GUPS_DATA_DIR "$PROFILE\GUPSGIS\gupsdata"
SectionEnd
Section "Uninstall"
DeleteRegKey HKLM "Software\GUPSTEST"
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\GUPSTEST"
SectionEnd
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecGUPSDATA} "Install GUPSDATA"
!insertmacro MUI_DESCRIPTION_TEXT ${SecRegUp} "Install GUPS Test Registry Entriessu"
!insertmacro MUI_DESCRIPTION_TEXT ${SecTEXTFILE} "Install Text File"
!insertmacro MUI_FUNCTION_DESCRIPTION_END
Update: I've tried the following this code example which is also failing to write registry entries.
# This installs two files, gupsdata\gupsdata.db and logo.ico, creates a start menu shortcut, builds an uninstaller, and
# adds uninstall information to the registry for Add/Remove Programs
# To get started, put this script into a folder with the two files (gupsdata\gupsdata.db, logo.ico, and license.rtf -
# You'll have to create these yourself) and run makensis on it
# If you change the names "gupsdata\gupsdata.db", "logo.ico", or "license.rtf" you should do a search and replace - they
# show up in a few places.
# All the other settings can be tweaked by editing the !defines at the top of this script
!define APPNAME "App Name"
!define COMPANYNAME "Company Name"
!define DESCRIPTION "A short description goes here"
# These three must be integers
!define VERSIONMAJOR 1
!define VERSIONMINOR 1
!define VERSIONBUILD 1
# These will be displayed by the "Click here for support information" link in "Add/Remove Programs"
# It is possible to use "mailto:" links in here to open the email client
!define HELPURL "http://..." # "Support Information" link
!define UPDATEURL "http://..." # "Product Updates" link
!define ABOUTURL "http://..." # "Publisher" link
# This is the size (in kB) of all the files copied into "Program Files"
!define INSTALLSIZE 12228
RequestExecutionLevel admin ;Require admin rights on NT6+ (When UAC is turned on)
InstallDir "$PROGRAMFILES\${COMPANYNAME}\${APPNAME}"
# rtf or txt file - remember if it is txt, it must be in the DOS text format (\r\n)
LicenseData "license.rtf"
# This will be in the installer/uninstaller's title bar
Name "${COMPANYNAME} - ${APPNAME}"
Icon "logo.ico"
outFile "sample-installer.exe"
!include LogicLib.nsh
# Just three pages - license agreement, install location, and installation
page license
page directory
Page instfiles
!macro VerifyUserIsAdmin
UserInfo::GetAccountType
pop $0
${If} $0 != "admin" ;Require admin rights on NT4+
messageBox mb_iconstop "Administrator rights required!"
setErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
quit
${EndIf}
!macroend
function .onInit
setShellVarContext all
!insertmacro VerifyUserIsAdmin
functionEnd
section "install"
# Files for the install directory - to build the installer, these should be in the same directory as the install script (this file)
setOutPath $INSTDIR
# Files added here should be removed by the uninstaller (see section "uninstall")
file "gupsdata\gupsdata.db"
file "logo.ico"
# Add any other files for the install directory (license files, app data, etc) here
# Uninstaller - See function un.onInit and section "uninstall" for configuration
writeUninstaller "$INSTDIR\uninstall.exe"
# Start Menu
createDirectory "$SMPROGRAMS\${COMPANYNAME}"
createShortCut "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk" "$INSTDIR\gupsdata\gupsdata.db" "" "$INSTDIR\logo.ico"
# Registry information for add/remove programs
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayName" "${COMPANYNAME} - ${APPNAME} - ${DESCRIPTION}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "UninstallString" "$\"$INSTDIR\uninstall.exe$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "QuietUninstallString" "$\"$INSTDIR\uninstall.exe$\" /S"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "InstallLocation" "$\"$INSTDIR$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayIcon" "$\"$INSTDIR\logo.ico$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "Publisher" "$\"${COMPANYNAME}$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "HelpLink" "$\"${HELPURL}$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLUpdateInfo" "$\"${UPDATEURL}$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "URLInfoAbout" "$\"${ABOUTURL}$\""
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "DisplayVersion" "$\"${VERSIONMAJOR}.${VERSIONMINOR}.${VERSIONBUILD}$\""
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMajor" ${VERSIONMAJOR}
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "VersionMinor" ${VERSIONMINOR}
# There is no option for modifying or repairing the install
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "NoRepair" 1
# Set the INSTALLSIZE constant (!defined at the top of this script) so Add/Remove Programs can accurately report the size
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}" "EstimatedSize" ${INSTALLSIZE}
sectionEnd
# Uninstaller
function un.onInit
SetShellVarContext all
#Verify the uninstaller - last chance to back out
MessageBox MB_OKCANCEL "Permanantly remove ${APPNAME}?" IDOK next
Abort
next:
!insertmacro VerifyUserIsAdmin
functionEnd
section "uninstall"
# Remove Start Menu launcher
delete "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}.lnk"
# Try to remove the Start Menu folder - this will only happen if it is empty
rmDir "$SMPROGRAMS\${COMPANYNAME}"
# Remove files
delete $INSTDIR\gupsdata\gupsdata.db
delete $INSTDIR\logo.ico
# Always delete uninstaller as the last action
delete $INSTDIR\uninstall.exe
# Try to remove the install directory - this will only happen if it is empty
rmDir $INSTDIR
# Remove uninstaller information from the registry
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${COMPANYNAME} ${APPNAME}"
sectionEnd
Operator error. Answer discovered in this post.
It's a 32 bit vs. 64 bit thing. My initial code was writing entries to the registry. I was looking for them in the wrong place. 32 bit entries get written to HKLM\Software\Wow6432Node rather than HKLM\Software.
For 64 bit applications, use SetRegView 64
in both the .onInit and the un.onInit functions.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With