WISDOMBAY

in4mation ... organized

Dealing with NSIS made Simpler

Page 3

Posted by Mohammed Arfath

; Write the uninstall keys for Windows
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${product_name}" "DisplayName" "${product_name}"
WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${product_name}" "UninstallString" '"$OUTDIR\uninstall.exe"'
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${product_name}" "NoModify" 1
WriteRegDWORD HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${product_name}" "NoRepair" 1
WriteUninstaller "$OUTDIR\uninstall.exe"
sectionend

Section "Start Menu Shortcuts" SecsmShortcuts
SetDetailsPrint textonly
DetailPrint "Installing Start Menu Shortcuts..."
SetDetailsPrint listonly
CreateDirectory "$SMPROGRAMS\${product_name}"
CreateShortCut "$SMPROGRAMS\${product_name}\${product_name}.lnk" "$OUTDIR\${application_name}" ""
CreateShortCut "$SMPROGRAMS\${product_name}\Uninstall ${product_name}.lnk" "$OUTDIR\uninstall.exe"
SectionEnd

Section "Desktop Shortcuts" SecdtShortcuts
SetDetailsPrint textonly
DetailPrint "Installing Desktop Shortcut..."
SetDetailsPrint listonly
CreateShortCut "$DESKTOP\${product_name}.lnk" "$OUTDIR\${application_name}" ""
SetDetailsPrint textonly
DetailPrint "Installing application files"
SetDetailsPrint listonly
SectionEnd

;The following code sets the message that should be displayed when the mouse pointer is placed over the options(ie the sections we added)
!insertmacro MUI_FUNCTION_DESCRIPTION_BEGIN
!insertmacro MUI_DESCRIPTION_TEXT ${SecsmShortcuts} "Adds icons to your start menu for easy access"
!insertmacro MUI_DESCRIPTION_TEXT ${SecdtShortcuts} "Adds icons to your desktop for easy access"
!insertmacro MUI_FUNCTION_DESCRIPTION_END

;;this section executes in the uninstaller
Section "Uninstall"
; Remove registry keys
DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${product_name}"
DeleteRegKey HKLM "SOFTWARE\${product_name}"
Delete "$SMPROGRAMS\${product_name}\Uninstall.lnk"
Delete "$SMPROGRAMS\${product_name}\${product_name}.lnk"
Delete "$DESKTOP\${product_name}.lnk"
;--------------------------------------------------------
; Remove shortcuts, if any
Delete "$SMPROGRAMS\${product_name}\*.*"

; Remove files and uninstaller
Delete $OUTDIR\uninstall.exe
Delete $OUTDIR\*.*

; Remove directories used
RMDir /r "$SMPROGRAMS\${product_name}"
RMDir /r "$OUTDIR"
SectionEnd

Function .onInit
;Checking If any instances of this program is already in execution
System::Call 'kernel32::CreateMutexA(i 0, i 0, t "instancecheck") i .r1 ?e'
Pop $R0
StrCmp $R0 0 +3
MessageBox MB_OK|MB_ICONEXCLAMATION "The installer is already running."
Abort

Google