Advertisement
Guest User

InstallSingleUser.nsi v1

a guest
Oct 12th, 2010
635
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*** InstallSingleUser.nsi ***
  2.  
  3. Tips:
  4. =====
  5. *Don't write to shared areas ($ProgramFiles, $WinDir, Registry\HKLM, Registry\HKCR etc)
  6.  
  7.  
  8. History:
  9. ========
  10. v1.0 [Anders]
  11. *Initial Version
  12.  
  13. */
  14.  
  15. !define APPNAME "FooBarBaz"
  16. ;You could use APPNAME here, but a GUID is guaranteed to be unique, use guidgen.com to create your own
  17. !define REGUINSTKEY "{2C82DD06-21E9-4602-8C2B-266AD720951B}"
  18.  
  19. Outfile "${APPNAME} setup.exe"
  20. Name "${APPNAME}"
  21. RequestExecutionLevel user
  22.  
  23. InstallDirRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" UninstallString
  24.  
  25. !define FOLDERID_UserProgramFiles {5CD7AEE2-2219-4A67-B85D-6C9CE15660CB}
  26. !define KF_FLAG_CREATE 0x00008000
  27.  
  28. !include LogicLib.nsh
  29. !include WinVer.nsh
  30. !include MUI2.nsh
  31.  
  32. Var SMDir ;Start menu folder
  33.  
  34. Function .onInit
  35. ;Default $Instdir (UserProgramFiles is %LOCALAPPDATA%\Programs by default, so we use that as our default)
  36. StrCpy $0 "$LocalAppData\Programs"
  37.  
  38. ;Make sure we don't overwrite $Instdir if specified on the command line or from InstallDirRegKey
  39. ${If} $Instdir == ""
  40.     ${If} ${IsNT}
  41.         ;Win7 has a per-user programfiles known folder and this could be a non-default location?
  42.         System::Call 'Shell32::SHGetKnownFolderPath(g "${FOLDERID_UserProgramFiles}",i ${KF_FLAG_CREATE},i0,*i.r2)i.r1'
  43.         ${If} $1 == 0
  44.             System::Call '*$2(&w${NSIS_MAX_STRLEN} .r1)'
  45.             StrCpy $0 $1
  46.             System::Call 'Ole32::CoTaskMemFree(ir2)'
  47.         ${EndIf}
  48.     ${Else}
  49.         ;Everyone is admin on Win9x, so falling back to $ProgramFiles is ok
  50.         ${IfThen} $LocalAppData == "" ${|} StrCpy $0 $ProgramFiles ${|}
  51.     ${EndIf}
  52.     StrCpy $Instdir "$0\${APPNAME}"
  53. ${EndIf}
  54. FunctionEnd
  55.  
  56.  
  57. !insertmacro MUI_PAGE_WELCOME
  58. #!insertmacro MUI_PAGE_COMPONENTS ;This example does not have separate components
  59. !insertmacro MUI_PAGE_DIRECTORY
  60. !insertmacro MUI_PAGE_STARTMENU 0 $SMDir
  61. !insertmacro MUI_PAGE_INSTFILES
  62. !insertmacro MUI_PAGE_FINISH
  63.  
  64. !insertmacro MUI_UNPAGE_WELCOME
  65. !insertmacro MUI_UNPAGE_CONFIRM
  66. !insertmacro MUI_UNPAGE_INSTFILES
  67.  
  68. !insertmacro MUI_LANGUAGE "English"
  69.  
  70. Section "Required Files"
  71. SectionIn RO
  72. SetOutPath $InstDir
  73. ###TODO: File MyApp.exe
  74.  
  75. WriteUninstaller "$InstDir\uninstall.exe"
  76. WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" UninstallString '"$InstDir\uninstall.exe"'
  77. WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" DisplayName "${APPNAME}"
  78. SectionEnd
  79.  
  80. Section -StartMenu
  81. !insertmacro MUI_STARTMENU_WRITE_BEGIN 0
  82. CreateDirectory "$SMPrograms\$SMDir"
  83. ###TODO: CreateShortcut "$SMPrograms\$SMDir\${APPNAME}.lnk" '"$Instdir\MyApp.exe"'
  84.  
  85. ;We need to save the startmenu folder so we can remove the shortcut in the uninstaller
  86. WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" "NSIS:SMDir" $SMDir
  87. !insertmacro MUI_STARTMENU_WRITE_END
  88. SectionEnd
  89.  
  90.  
  91. Section Uninstall
  92. ReadRegStr $SMDir HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}" "NSIS:SMDir"
  93. ${If} $SMDir != ""
  94.     ###TODO: Delete "$SMPrograms\$SMDir\${APPNAME}.lnk"
  95.     RMDir "$SMPrograms\$SMDir"
  96. ${EndIf}
  97.  
  98. DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\${REGUINSTKEY}"
  99.  
  100. ###TODO: Delete "$InstDir\MyApp.exe"
  101. Delete "$InstDir\uninstall.exe"
  102. RMDir "$InstDir"
  103. SectionEnd
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement