杉宫竹苑工作室

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 1990|回复: 0

使用NSIS制作安装包

[复制链接]
发表于 2016-9-2 14:44:27 | 显示全部楼层 |阅读模式

正式会员享受无限制浏览网站功能和高速网盘下载,赶快加入本站吧!

您需要 登录 才可以下载或查看,没有账号?立即注册

x
  1. !include WordFunc.nsh
  2. !insertmacro VersionCompare
  3. !include LogicLib.nsh

  4. Name ".NET运行库"
  5. OutFile "DotNetSetup.exe"

  6. var "DOTNETFX_RETURN_CODE"
  7. var "DOTNETLang_RETURN_CODE"
  8. var "ERROR_DOTNET_FATAL"
  9. var "INSTALL_SUCCESS"

  10. Function .onInit
  11.     StrCpy $ERROR_DOTNET_FATAL "在安装.NET运行库时出现一个严重的错误,安装.NET运行库失败!"
  12.     StrCpy $INSTALL_SUCCESS "安装成功!"
  13.    
  14.     Call GetDotNETVersion
  15.     pop $0
  16.     ${If} $0 == "not found"
  17.         Call InstallDotNetFx
  18.         pop $DOTNETFX_RETURN_CODE
  19.         ${If} $DOTNETFX_RETURN_CODE <> 0
  20.             MessageBox MB_OK|MB_ICONSTOP $ERROR_DOTNET_FATAL
  21.             Abort
  22.         ${EndIf}
  23.         
  24.         Call InstallDotNetLang
  25.         pop $DOTNETLang_RETURN_CODE
  26.         ${If} $DOTNETLang_RETURN_CODE <> 0
  27.             MessageBox MB_OK|MB_ICONINFORMATION $INSTALL_SUCCESS
  28.             Abort
  29.         ${EndIf}
  30.     ${EndIf}

  31.     StrCpy $0 $0 "" 1 # skip "v"

  32.     ${VersionCompare} $0 "2.0" $1
  33.     ${If} $1 == 2
  34.         Call InstallDotNetFx
  35.         pop $DOTNETFX_RETURN_CODE
  36.         ${If} $DOTNETFX_RETURN_CODE <> 0
  37.             MessageBox MB_OK|MB_ICONSTOP $ERROR_DOTNET_FATAL
  38.             Abort
  39.         ${EndIf}

  40.         Call InstallDotNetLang
  41.         pop $DOTNETLang_RETURN_CODE
  42.         ${If} $DOTNETLang_RETURN_CODE <> 0
  43.             MessageBox MB_OK|MB_ICONINFORMATION $INSTALL_SUCCESS
  44.             Abort
  45.         ${EndIf}
  46.     ${EndIf}
  47. FunctionEnd
  48. ;获取.NET版本,此函数在nsis.sf.net中有
  49. Function GetDotNETVersion
  50.     Push $0
  51.     Push $1

  52.     System::Call "mscoree::GetCORVersion(w .r0, i ${NSIS_MAX_STRLEN}, *i) i .r1"
  53.     StrCmp $1 "error" 0 +2
  54.     StrCpy $0 "not found"

  55.     Pop $1
  56.     Exch $0
  57. FunctionEnd
  58. ;安装.NET框架
  59. Function InstallDotNetFx
  60.     push $DOTNETFX_RETURN_CODE
  61.     StrCpy $DOTNETFX_RETURN_CODE "0"
  62.     SetOutPath "$PLUGINSDIR"
  63.     File /r "dotnetfx.exe"
  64.     Banner::show /NOUNLOAD "正在安装.NET运行库..."
  65.     nsExec::ExecToStack '"dotnetfx.exe" /q /c:"install.exe /noaspupgrade /q"'
  66.     ;pop $DOTNETFX_RETURN_CODE
  67.     Banner::destroy
  68. FunctionEnd
  69. ;安装语言包
  70. Function InstallDotNetLang
  71.     push $DOTNETLang_RETURN_CODE
  72.     StrCpy $DOTNETLang_RETURN_CODE "0"
  73.     SetOutPath "$PLUGINSDIR"
  74.     File /r "langpack.exe"
  75.     Banner::show /NOUNLOAD "正在安装.NET运行库中文语言包..."
  76.     nsExec::ExecToStack '"langpack.exe" /q /c:"install.exe /noaspupgrade /q"'
  77.     ;pop $DOTNETLang_RETURN_CODE
  78.     Banner::destroy
  79. FunctionEnd

  80. Section
  81. SectionEnd
复制代码


回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|小黑屋|手机版|Archiver|SgzyStudio

GMT+8, 2024-5-17 08:16 , Processed in 0.108601 second(s), 18 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表