Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*** InstallAllUsers.nsi ***
- Tips:
- =====
- *Don't write to per-user areas ($[Local]Appdata, Registry\HKCU etc)
- *Don't use MUI_FINISHPAGE_RUN_xxx
- 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 "{7c346d98-4eb2-4b40-97bd-e8e06dc52bc7}"
- Outfile "${APPNAME} setup.exe"
- Name "${APPNAME}"
- RequestExecutionLevel admin
- InstallDir "$ProgramFiles\${APPNAME}"
- InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" UninstallString
- !include LogicLib.nsh
- !include MUI2.nsh
- Var SMDir ;Start menu folder
- !macro CommonOnInit runmode
- SetShellVarContext all
- UserInfo::GetAccountType
- pop $0
- ${If} $0 != "Admin"
- MessageBox mb_iconstop "Administrator rights required to ${runmode} ${APPNAME}!"
- SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
- Quit
- ${EndIf}
- !macroend
- Function .onInit
- !insertmacro CommonOnInit "install"
- FunctionEnd
- Function un.onInit
- !insertmacro CommonOnInit "uninstall"
- 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 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" UninstallString '"$InstDir\uninstall.exe"'
- WriteRegStr HKLM "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 HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" "NSIS:SMDir" $SMDir
- !insertmacro MUI_STARTMENU_WRITE_END
- SectionEnd
- Section Uninstall
- ReadRegStr $SMDir HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" "NSIS:SMDir"
- ${If} $SMDir != ""
- ###TODO: Delete "$SMPrograms\$SMDir\${APPNAME}.lnk"
- RMDir "$SMPrograms\$SMDir"
- ${EndIf}
- DeleteRegKey HKLM "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