Advertisement
Guest User

Untitled

a guest
Jun 20th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*** InstallAllUsers.nsi ***
  2.  
  3. Tips:
  4. =====
  5. *Don't write to per-user areas ($[Local]Appdata, Registry\HKCU etc)
  6. *Don't use MUI_FINISHPAGE_RUN_xxx
  7.  
  8.  
  9. History:
  10. ========
  11. v1.0 [Anders]
  12. *Initial Version
  13.  
  14. */
  15.  
  16. !define APPNAME "FooBarBaz"
  17. ;You could use APPNAME here, but a GUID is guaranteed to be unique, use guidgen.com to create your own
  18. !define REGUINSTKEY "{7c346d98-4eb2-4b40-97bd-e8e06dc52bc7}"
  19.  
  20. Outfile "${APPNAME} setup.exe"
  21. Name "${APPNAME}"
  22. RequestExecutionLevel admin
  23.  
  24. InstallDir "$ProgramFiles\${APPNAME}"
  25. InstallDirRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" UninstallString
  26.  
  27. !include LogicLib.nsh
  28. !include MUI2.nsh
  29.  
  30. Var SMDir ;Start menu folder
  31.  
  32. !macro CommonOnInit runmode
  33. SetShellVarContext all
  34.  
  35. UserInfo::GetAccountType
  36. pop $0
  37. ${If} $0 != "Admin"
  38.     MessageBox mb_iconstop "Administrator rights required to ${runmode} ${APPNAME}!"
  39.     SetErrorLevel 740 ;ERROR_ELEVATION_REQUIRED
  40.     Quit
  41. ${EndIf}
  42. !macroend
  43.  
  44. Function .onInit
  45. !insertmacro CommonOnInit "install"
  46. FunctionEnd
  47. Function un.onInit
  48. !insertmacro CommonOnInit "uninstall"
  49. FunctionEnd
  50.  
  51.  
  52. !insertmacro MUI_PAGE_WELCOME
  53. #!insertmacro MUI_PAGE_COMPONENTS ;This example does not have separate components
  54. !insertmacro MUI_PAGE_DIRECTORY
  55. !insertmacro MUI_PAGE_STARTMENU 0 $SMDir
  56. !insertmacro MUI_PAGE_INSTFILES
  57. !insertmacro MUI_PAGE_FINISH
  58.  
  59. !insertmacro MUI_UNPAGE_WELCOME
  60. !insertmacro MUI_UNPAGE_CONFIRM
  61. !insertmacro MUI_UNPAGE_INSTFILES
  62.  
  63. !insertmacro MUI_LANGUAGE "English"
  64.  
  65. Section "Required Files"
  66. SectionIn RO
  67. SetOutPath $InstDir
  68. ###TODO: File MyApp.exe
  69.  
  70. WriteUninstaller "$InstDir\uninstall.exe"
  71. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" UninstallString '"$InstDir\uninstall.exe"'
  72. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" DisplayName "${APPNAME}"
  73. SectionEnd
  74.  
  75. Section -StartMenu
  76. !insertmacro MUI_STARTMENU_WRITE_BEGIN 0
  77. CreateDirectory "$SMPrograms\$SMDir"
  78. ###TODO: CreateShortcut "$SMPrograms\$SMDir\${APPNAME}.lnk" '"$Instdir\MyApp.exe"'
  79.  
  80. ;We need to save the startmenu folder so we can remove the shortcut in the uninstaller
  81. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" "NSIS:SMDir" $SMDir
  82. !insertmacro MUI_STARTMENU_WRITE_END
  83. SectionEnd
  84.  
  85.  
  86. Section Uninstall
  87. ReadRegStr $SMDir HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" "NSIS:SMDir"
  88. ${If} $SMDir != ""
  89.     ###TODO: Delete "$SMPrograms\$SMDir\${APPNAME}.lnk"
  90.     RMDir "$SMPrograms\$SMDir"
  91. ${EndIf}
  92.  
  93. DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}"
  94.  
  95. ###TODO: Delete "$InstDir\MyApp.exe"
  96. Delete "$InstDir\uninstall.exe"
  97. RMDir "$InstDir"
  98. SectionEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement