现在.NET开发的软件已经大行其道,但有些操作系统并不符合软件的运行要求,所以,我们需要在安装程序中进行.NET Framework的判断,如果不符合要求就进行静默安装。
首先,我们在Function区段进行当前.NET版本判断:
Function GetNetFrameworkVersion;获取.Net Framework版本,支持Push $1Push $0ReadRegDWORD $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 +1ReadRegDWORD $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 +1ReadRegDWORD $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 +2StrCpy $1 "2.0.50727.832"StrCmp $0 1 KnowNetFrameworkVersion +1ReadRegDWORD $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 +2StrCpy $1 "1.1.4322.573"StrCmp $0 1 KnowNetFrameworkVersion +1ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\.NETFramework\policy\v1.0" "Install"ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\.NETFramework\policy\v1.0" "Version"StrCmp $1 "" +1 +2StrCpy $1 "1.0.3705.0"StrCmp $0 1 KnowNetFrameworkVersion +1StrCpy $1 "not .NetFramework"KnowNetFrameworkVersion:Pop $0Exch $1FunctionEnd
然后,在Section区段进行.NET静默安装
Section -.NETCall GetNetFrameworkVersionPop $R1 ${If} $R1 < '2.0.50727' SetDetailsPrint textonly DetailPrint "正在安装 .NET Framework 2.0 SP2..." SetDetailsPrint listonly
SetOutPath "$TEMP" SetOverwrite on File "NetFx20SP2_x86.exe" ExecWait '$TEMP\NetFx20SP2_x86.exe /quiet /norestart' $R1 Delete "$TEMP\NetFx20SP2_x86.exe" ${EndIf}SectionEnd
当然,在Section区段可以做到自动在线下载而不把.NET打到安装包中,这样可以减小安装包体积,效果可参考紫辰记账本安装程序。
转载自:http://www.flighty.cn/html/bushu/20110527_126.html
转载于:https://www.cnblogs.com/wuhenke/archive/2011/05/31/2065220.html
相关资源:NSIS用户手册(中文版)