NSIS:判斷並安裝.NET Framework 4 的例子

原文 NSIS:判斷並安裝.NET Framework 4 的例子html

如今.NET開發的軟件已經大行其道,但有些操做系統並不符合軟件的運行要求,因此,咱們須要在安裝程序中進行.NET Framework的判斷,若是不符合要求就進行靜默安裝。app

 

首先,咱們在Function區段進行當前.NET版本判斷:spa

 Function GetNetFrameworkVersion 02 ;獲取.Net Framework版本支持 03 Push $1
04 Push $0
05 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full""Install"
06 ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full""Version"
07 StrCmp $0 1 KnowNetFrameworkVersion +1
08 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5""Install"
09 ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5""Version"
10 StrCmp $0 1 KnowNetFrameworkVersion +1
11 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup" "InstallSuccess"
12 ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0\Setup" "Version"
13 StrCmp $0 1 KnowNetFrameworkVersion +1
14 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" "Install"
15 ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727" "Version"
16 StrCmp $1 "" +1 +2
17 StrCpy $1 "2.0.50727.832"
18 StrCmp $0 1 KnowNetFrameworkVersion +1
19 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322" "Install"
20 ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\NET Framework Setup\NDP\v1.1.4322" "Version"
21 StrCmp $1 "" +1 +2
22 StrCpy $1 "1.1.4322.573"
23 StrCmp $0 1 KnowNetFrameworkVersion +1
24 ReadRegDWORD $0 HKLM "SOFTWARE\Microsoft\.NETFramework\policy\v1.0""Install"
25 ReadRegDWORD $1 HKLM "SOFTWARE\Microsoft\.NETFramework\policy\v1.0""Version"
26 StrCmp $1 "" +1 +2
27 StrCpy $1 "1.0.3705.0"
28 StrCmp $0 1 KnowNetFrameworkVersion +1
29 StrCpy $1 "not .NetFramework"
30 KnowNetFrameworkVersion: 31 Pop $0
32 Exch $1
33 FunctionEnd

而後,在Section區段進行.NET靜默安裝:操作系統

01 Section -.NET 02 Call GetNetFrameworkVersion 03 Pop $R1 04 ${If} $R1 < '4.0.30319'
05 SetDetailsPrint textonly 06 DetailPrint "正在安裝 .NET Framework 4"
07 SetDetailsPrint listonly 08
 
09 SetOutPath "$TEMP"
10 SetOverwrite on 11 File "dotNetFx40_Full_x86_x64.exe"
12 ExecWait '$TEMP\dotNetFx40_Full_x86_x64.exe /q /norestart /ChainingPackage FullX64Bootstrapper' $R1 13 Delete "$TEMP\dotNetFx40_Full_x86_x64.exe"
14 ${EndIf} 15 SectionEnd

固然,在Section區段能夠作到自動在線下載而不把.NET打到安裝包中,這樣能夠減少安裝包體積,效果可參考紫辰記帳本安裝程序rest

相關文章
相關標籤/搜索