Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*** InstallSingleUser.nsi ***
- Tips:
- =====
- *Don't write to shared areas ($ProgramFiles, $WinDir, Registry\HKLM, Registry\HKCR etc)
- History:
- ========
- v1.0 [Anders]
- *Initial Version
- */
- !define APPNAME "FooBarBaz"
- ;You could use APPNAME here, but a GUID is guaranteed to be unique, use guidgen.com to create your own
- !define REGUINSTKEY "{2C82DD06-21E9-4602-8C2B-266AD720951B}"
- Outfile "${APPNAME} setup.exe"
- Name "${APPNAME}"
- RequestExecutionLevel user
- InstallDirRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" UninstallString
- !define FOLDERID_UserProgramFiles {5CD7AEE2-2219-4A67-B85D-6C9CE15660CB}
- !define KF_FLAG_CREATE 0x00008000
- !include LogicLib.nsh
- !include WinVer.nsh
- !include MUI2.nsh
- Var SMDir ;Start menu folder
- Function .onInit
- ;Default $Instdir (UserProgramFiles is %LOCALAPPDATA%\Programs by default, so we use that as our default)
- StrCpy $0 "$LocalAppData\Programs"
- ;Make sure we don't overwrite $Instdir if specified on the command line or from InstallDirRegKey
- ${If} $Instdir == ""
- ${If} ${IsNT}
- ;Win7 has a per-user programfiles known folder and this could be a non-default location?
- System::Call 'Shell32::SHGetKnownFolderPath(g "${FOLDERID_UserProgramFiles}",i ${KF_FLAG_CREATE},i0,*i.r2)i.r1'
- ${If} $1 == 0
- System::Call '*$2(&w${NSIS_MAX_STRLEN} .r1)'
- StrCpy $0 $1
- System::Call 'Ole32::CoTaskMemFree(ir2)'
- ${EndIf}
- ${Else}
- ;Everyone is admin on Win9x, so falling back to $ProgramFiles is ok
- ${IfThen} $LocalAppData == "" ${|} StrCpy $0 $ProgramFiles ${|}
- ${EndIf}
- StrCpy $Instdir "$0\${APPNAME}"
- ${EndIf}
- FunctionEnd
- !insertmacro MUI_PAGE_WELCOME
- #!insertmacro MUI_PAGE_COMPONENTS ;This example does not have separate components
- !insertmacro MUI_PAGE_DIRECTORY
- !insertmacro MUI_PAGE_STARTMENU 0 $SMDir
- !insertmacro MUI_PAGE_INSTFILES
- !insertmacro MUI_PAGE_FINISH
- !insertmacro MUI_UNPAGE_WELCOME
- !insertmacro MUI_UNPAGE_CONFIRM
- !insertmacro MUI_UNPAGE_INSTFILES
- !insertmacro MUI_LANGUAGE "English"
- Section "Required Files"
- SectionIn RO
- SetOutPath $InstDir
- ###TODO: File MyApp.exe
- WriteUninstaller "$InstDir\uninstall.exe"
- WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" UninstallString '"$InstDir\uninstall.exe"'
- WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" DisplayName "${APPNAME}"
- SectionEnd
- Section -StartMenu
- !insertmacro MUI_STARTMENU_WRITE_BEGIN 0
- CreateDirectory "$SMPrograms\$SMDir"
- ###TODO: CreateShortcut "$SMPrograms\$SMDir\${APPNAME}.lnk" '"$Instdir\MyApp.exe"'
- ;We need to save the startmenu folder so we can remove the shortcut in the uninstaller
- WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" "NSIS:SMDir" $SMDir
- !insertmacro MUI_STARTMENU_WRITE_END
- SectionEnd
- Section Uninstall
- ReadRegStr $SMDir HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" "NSIS:SMDir"
- ${If} $SMDir != ""
- ###TODO: Delete "$SMPrograms\$SMDir\${APPNAME}.lnk"
- RMDir "$SMPrograms\$SMDir"
- ${EndIf}
- DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}"
- ###TODO: Delete "$InstDir\MyApp.exe"
- Delete "$InstDir\uninstall.exe"
- RMDir "$InstDir"
- SectionEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement