最新消息:

判断并安装.NET Framework 4 的例子

nsis 永恒心锁 2158浏览 0评论

现在.NET开发的软件已经大行其道,但有些操作系统并不符合软件的运行要求,所以,我们需要在安装程序中进行.NET Framework的判断,如果不符合要求就进行静默安装。

 

首先,我们在Function区段进行当前.NET版本判断:

Function GetNetFrameworkVersion
;获取.Net Framework版本支持
Push $1
Push $0
ReadRegDWORD $0 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv4Full" "Install"
ReadRegDWORD $1 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv4Full" "Version"
StrCmp $0 1 KnowNetFrameworkVersion +1
ReadRegDWORD $0 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv3.5" "Install"
ReadRegDWORD $1 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv3.5" "Version"
StrCmp $0 1 KnowNetFrameworkVersion +1
ReadRegDWORD $0 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv3.0Setup" "InstallSuccess"
ReadRegDWORD $1 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv3.0Setup" "Version"
StrCmp $0 1 KnowNetFrameworkVersion +1
ReadRegDWORD $0 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv2.0.50727" "Install"
ReadRegDWORD $1 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv2.0.50727" "Version"
StrCmp $1 "" +1 +2
StrCpy $1 "2.0.50727.832"
StrCmp $0 1 KnowNetFrameworkVersion +1
ReadRegDWORD $0 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv1.1.4322" "Install"
ReadRegDWORD $1 HKLM "SOFTWAREMicrosoftNET Framework SetupNDPv1.1.4322" "Version"
StrCmp $1 "" +1 +2
StrCpy $1 "1.1.4322.573"
StrCmp $0 1 KnowNetFrameworkVersion +1
ReadRegDWORD $0 HKLM "SOFTWAREMicrosoft.NETFrameworkpolicyv1.0" "Install"
ReadRegDWORD $1 HKLM "SOFTWAREMicrosoft.NETFrameworkpolicyv1.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

然后,在Section区段进行.NET静默安装:当然,在Section区段可以做到自动在线下载而不把.NET打到安装包中,这样可以减小安装包体积.

Section -.NET
Call GetNetFrameworkVersion
Pop $R1
 ${If} $R1 < '4.0.30319'
 SetDetailsPrint textonly
 DetailPrint "正在安装 .NET Framework 4"
 SetDetailsPrint listonly

 SetOutPath "$TEMP"
 SetOverwrite on
 File "dotNetFx40_Full_x86_x64.exe"
 ExecWait '$TEMPdotNetFx40_Full_x86_x64.exe /q /norestart /ChainingPackage FullX64Bootstrapper' $R1
 Delete "$TEMPdotNetFx40_Full_x86_x64.exe"
 ${EndIf}
SectionEnd
免责声明:根据《计算机软件保护条例》第十七条规定“为了学习和研究软件内含的设计思想和原理,通过安装、显示、传输或者存储软件等方式使用软件的,可以不经软件著作权人许可,不向其支付报酬。”您需知晓本站所有内容资源均来源于网络,仅供用户交流学习与研究使用,版权归属原版权方所有,版权争议与本站无关,用户本人下载后不能用作商业或非法用途,需在24个小时之内从您的电脑中彻底删除上述内容,否则后果均由用户承担责任;如果您访问和下载此文件,表示您同意只将此文件用于参考、学习而非其他用途,否则一切后果请您自行承担,如果您喜欢该程序,请支持正版软件,购买注册,得到更好的正版服务。丨本站为个人博客非盈利性站点,所有软件信息均来自网络,所有资源仅供学习参考研究目的,并不贩卖软件,不存在任何商业目的及用途。丨本文采用知识共享 署名4.0国际许可协议 [BY-NC-SA] 进行授权BY-NC-SA协议进行授权

转载请注明:永恒心锁-分享互联网 » 判断并安装.NET Framework 4 的例子

发表我的评论
取消评论
表情

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址