NSIS使用记录

; 该脚本使用 HM VNISEdit 脚本编辑器向导产生 ; 安装程序初始定义常量 !define PRODUCT_NAME ""
!define PRODUCT_VERSION "1.0"
!define PRODUCT_PUBLISHER " Inc."
!define PRODUCT_UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\${PRODUCT_NAME}"
!define PRODUCT_UNINST_ROOT_KEY "HKLM" SetCompressor lzma ; ------ MUI 现代界面定义 (1.67 版本以上兼容) ------
!include "MUI.nsh" ; MUI 预定义常量 !define MUI_ABORTWARNING !define MUI_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!define MUI_UNICON "${NSISDIR}\Contrib\Graphics\Icons\modern-uninstall.ico" ; 语言选择窗口常量设置 !define MUI_LANGDLL_REGISTRY_ROOT "${PRODUCT_UNINST_ROOT_KEY}"
!define MUI_LANGDLL_REGISTRY_KEY "${PRODUCT_UNINST_KEY}"
!define MUI_LANGDLL_REGISTRY_VALUENAME "NSIS:Language" ; 欢迎页面 !insertmacro MUI_PAGE_WELCOME ; 许可协议页面 ;!insertmacro MUI_PAGE_LICENSE "Licence.txt" ; 安装过程页面 !insertmacro MUI_PAGE_INSTFILES ; 安装完成页面 !define MUI_FINISHPAGE_RUN "$INSTDIR\WPF.exe"
!insertmacro MUI_PAGE_FINISH ; 安装卸载过程页面 !insertmacro MUI_UNPAGE_INSTFILES ; 安装界面包含的语言设置 !insertmacro MUI_LANGUAGE "English"
!insertmacro MUI_LANGUAGE "SimpChinese" ; 安装预释放文件 !insertmacro MUI_RESERVEFILE_LANGDLL !insertmacro MUI_RESERVEFILE_INSTALLOPTIONS ; ------ MUI 现代界面定义结束 ------ Name "${PRODUCT_NAME} ${PRODUCT_VERSION}" OutFile "Lane.exe" InstallDir "$PROGRAMFILES\Lane" ShowInstDetails show ShowUnInstDetails show BrandingText " " Section "MainSection" SEC01 SetOutPath "$INSTDIR" SetOverwrite ifnewer File /r "Release\*.*" SetOutPath "$INSTDIR\configs" ${If} $LANGUAGE == '2052' File "configs\zh-CN\app-config.xml" ${Else} File "configs\en-US\app-config.xml" ${EndIf} CreateDirectory "$SMPROGRAMS\Lane" /*所有程序文件夹*/ CreateShortCut "$SMPROGRAMS\Lane\Lane.lnk" "$INSTDIR\WPF.exe" /*所有程序--快捷方式*/ CreateShortCut "$DESKTOP\Lane.lnk" "$INSTDIR\WPF.exe" /*桌面--快捷方式*/ CreateShortCut "$SMSTARTUP\Lane.lnk" "$INSTDIR\WPF.exe" /*自启动--快捷方式*/ Call GetNetFrameworkVersion Pop $R1 ${If} $R1 < '2.0.50727' SetDetailsPrint textonly DetailPrint "正在安装 .NET Framework 2.0 SP2..." SetDetailsPrint listonly SetOutPath "$INSTDIR" SetOverwrite on File "Framwork2.0\dotnetfx.exe" ExecWait '"$INSTDIR\dotnetfx.exe"' Delete "$INSTDIR\dotnetfx.exe" ${ElseIf} $R1 < '3.0' File "Framwork2.0\dotnetfx.exe" ExecWait '"$INSTDIR\dotnetfx.exe"' Delete "$INSTDIR\dotnetfx.exe" ${ElseIf} $R1 < '3.5' File "Framwork2.0\dotnetfx.exe" ExecWait '"$INSTDIR\dotnetfx.exe"' Delete "$INSTDIR\dotnetfx.exe" ${ElseIf} $R1 < '4.0' File "Framwork2.0\dotnetfx.exe" ExecWait '"$INSTDIR\dotnetfx.exe"' Delete "$INSTDIR\dotnetfx.exe" ${ElseIf} $R1 < '4.5' File "Framwork2.0\dotnetfx.exe" ExecWait '"$INSTDIR\dotnetfx.exe"' Delete "$INSTDIR\dotnetfx.exe" ${EndIf} SectionEnd Section -AdditionalIcons CreateShortCut "$SMPROGRAMS\Lane\Uninstall.lnk" "$INSTDIR\uninst.exe" SectionEnd Section -Post WriteUninstaller "$INSTDIR\uninst.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayName" "$(^Name)" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "UninstallString" "$INSTDIR\uninst.exe" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "DisplayVersion" "${PRODUCT_VERSION}" WriteRegStr ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" "Publisher" "${PRODUCT_PUBLISHER}" SectionEnd #-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--# Function GetNetFrameworkVersion ;获取.Net Framework版本,支持 Push $1 Push $0 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Install" ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full" "Version" StrCmp $0 1 KnowNetFrameworkVersion +1 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0\Client" "Install" ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4.0\Client" "Version" StrCmp $0 1 KnowNetFrameworkVersion +1 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" "Install" ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5" "Version" StrCmp $0 1 KnowNetFrameworkVersion +1 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup" "InstallSuccess" ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup" "Version" StrCmp $0 1 KnowNetFrameworkVersion +1 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" "Install" ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" "Version" StrCmp $1 "" +1 +2 StrCpy $1 "2.0.50727.832" StrCmp $0 1 KnowNetFrameworkVersion +1 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322" "Install" ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322" "Version" StrCmp $1 "" +1 +2 StrCpy $1 "1.1.4322.573" StrCmp $0 1 KnowNetFrameworkVersion +1 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\.NETFramework\policy\v1.0" "Install" ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\.NETFramework\policy\v1.0" "Version" StrCmp $1 "" +1 +2 StrCpy $1 "1.0.3705.0" StrCmp $0 1 KnowNetFrameworkVersion +1 StrCpy $1 "not .NetFramework" KnowNetFrameworkVersion: Pop $0 Exch $1 FunctionEnd Function .onInit !insertmacro MUI_LANGDLL_DISPLAY FunctionEnd /****************************** * 以下是安装程序的卸载部分 * ******************************/ Section Uninstall Delete "$INSTDIR\uninst.exe" Delete "$SMPROGRAMS\Lane\Uninstall.lnk" Delete "$DESKTOP\Lane.lnk" Delete "$SMPROGRAMS\Lane\Lane.lnk" Delete "$SMSTARTUP\Lane.lnk" RMDir "$SMPROGRAMS\Lane" RMDir /r "$INSTDIR\zh-Hant" RMDir /r "$INSTDIR\zh-Hans" RMDir /r "$INSTDIR\Logs" RMDir /r "$INSTDIR\ko" RMDir /r "$INSTDIR\ja" RMDir /r "$INSTDIR\it" RMDir /r "$INSTDIR\fr" RMDir /r "$INSTDIR\es" RMDir /r "$INSTDIR\en" RMDir /r "$INSTDIR\de" RMDir /r "$INSTDIR\configs" RMDir /r "$INSTDIR" RMDir "$INSTDIR" DeleteRegKey ${PRODUCT_UNINST_ROOT_KEY} "${PRODUCT_UNINST_KEY}" SetAutoClose true SectionEnd #-- 根据 NSIS 脚本编辑规则,所有 Function 区段必须放置在 Section 区段之后编写,以避免安装程序出现未可预知的问题。--# Function un.onInit !insertmacro MUI_UNGETLANGUAGE MessageBox MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2 "您确实要完全移除 $(^Name) ,及其所有的组件?" IDYES +2 Abort FunctionEnd Function un.onUninstSuccess HideWindow MessageBox MB_ICONINFORMATION|MB_OK "$(^Name) 已成功地从您的计算机移除。" FunctionEnd

 

你可能感兴趣的:(使用)