據網上前人判斷.net版本改加入windows版本判斷而來。已測試通過!
; 腳本由 Inno Setup 腳本向導 生成!; 有關創建 Inno Setup 腳本文件的詳細資料請查閱幫助文檔!
[Code] //.net framework安裝檢查 —— 判斷指定的.NET Framework版本及service pack是否已經安裝// 函數參數說明:// 參數1:version -- 指定待判斷的.NET Framework版本【下面列舉了對應關系】:// 'v1.1' .NET Framework 1.1// 'v2.0' .NET Framework 2.0// 'v3.0' .NET Framework 3.0// 'v3.5' .NET Framework 3.5// 'v4\Client' .NET Framework 4.0 Client Profile// 'v4\Full' .NET Framework 4.0 Full Installation// 'v4.5' .NET Framework 4.5// 'v4.5.1' .NET Framework 4.5.1// 'v4.5.2' .NET Framework 4.5.2// 'v4.6' .NET Framework 4.6// 'v4.6.1' .NET Framework 4.6.1// 'v4.6.2' .NET Framework 4.6.2// 'v4.7' .NET Framework 4.7// 'v4.7.1' .NET Framework 4.7.1// 'v4.7.2' .NET Framework 4.7.2// `v4.8` .NET Framework 4.8//// 參數2:service -- 指定待判斷的service pack版本:// 0 No service packs required// 1, 2, etc. Service pack 1, 2, etc. requiredfunction IsDotNetDetected(version: string; service: cardinal): boolean;var key, versionKey: string; install, release, serviceCount, versionRelease: cardinal; success: boolean;begin versionKey :=version; versionRelease :=0; // .NET 1.1 and 2.0 embed release number in version key if version='v1.1' then begin versionKey :='v1.1.4322'; end else if version='v2.0' then begin versionKey :='v2.0.50727'; end // .NET 4.5 and newer install as update to .NET 4.0 Full else if Pos('v4.', version)=1 then begin versionKey :='v4\Full'; case version of 'v4.5': versionRelease :=378389; 'v4.5.1': versionRelease :=378675; // 378758 on Windows 8 and older 'v4.5.2': versionRelease :=379893; 'v4.6': versionRelease :=393295; // 393297 on Windows 8.1 and older 'v4.6.1': versionRelease :=394254; // 394271 before Win10 November Update 'v4.6.2': versionRelease :=394802; // 394806 before Win10 Anniversary Update 'v4.7': versionRelease :=460798; // 460805 before Win10 Creators Update 'v4.7.1': versionRelease :=461308; // 461310 before Win10 Fall Creators Update 'v4.7.2': versionRelease :=461808; // 461814 before Win10 April 2018 Update 'v4.8': versionRelease :=528040; end; end; // installation key group for all .NET versions key :='SOFTWARE\Microsoft\NET Framework Setup\NDP\' + versionKey; // .NET 3.0 uses value InstallSuccess in subkey Setup if Pos('v3.0', version)=1 then begin success :=RegQueryDWordValue(HKLM, key + '\Setup', 'InstallSuccess', install); end else begin success :=RegQueryDWordValue(HKLM, key, 'Install', install); end; // .NET 4.0 and newer use value Servicing instead of SP if Pos('v4', version)=1 then begin success :=success and RegQueryDWordValue(HKLM, key, 'Servicing', serviceCount); end else begin success :=success and RegQueryDWordValue(HKLM, key, 'SP', serviceCount); end; // .NET 4.5 and newer use additional value Release if versionRelease > 0 then begin success :=success and RegQueryDWordValue(HKLM, key, 'Release', release); success :=success and (release >=versionRelease); end; result :=success and (install=1) and (serviceCount >=service);end;//判斷windows版本function MyGetWindowsVersion: String; // 獲取 Windows 版本varVersion: TWindowsVersion;beginGetWindowsVersionEx(Version);// Windows7if (Version.Major=6) and (Version.Minor=0) thenbeginResult :='VISTA';Exit;end;// Windows7if (Version.Major=6) and (Version.Minor=1) thenbeginResult :='WIN7';Exit;end;// Windows XP if (Version.Major=5) and (Version.Minor >=1) thenbeginResult :='WINXP';Exit;end;// Windows 8 if (Version.Major=6) and (Version.Minor >1) thenbeginResult :='WIN8';Exit;end;// Windows 10if (Version.Major=10) thenbeginResult :='WIN10';Exit;end; end; // 根據不同windows版本,判斷所需的.netframework版本 function InitializeSetup: Boolean; var Path:string; ResultCode: Integer; Version: TWindowsVersion; begin GetWindowsVersionEx(Version); if (MyGetWindowsVersion='XP' ) then //或者 (Version.Major=5) begin if IsDotNetDetected('v4', 0) then begin Result :=true; End Else begin if MsgBox('系統檢測到您沒有安裝.Net Framework 4 版本,是否立刻下載并安裝?', mbConfirmation, MB_YESNO)=idYes then begin Path :=ExpandConstant('{pf}/Internet Explorer/iexplore.exe'); Exec(Path, 'http://download.microsoft.com/download/1/B/E/1BE39E79-7E39-46A3-96FF-047F95396215/dotNetFx40_Full_setup.exe', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode); MsgBox('請安裝好.Net Framework環境后(4.0client-4.0Full),再運行本安裝包程序!',mbInformation,MB_OK); Result :=false; Exit; End Else begin MsgBox('沒有安裝.Net Framework環境,無法運行程序,本安裝程序即將退出!',mbInformation,MB_OK); Result :=false; Exit; end; end; end else begin Result :=true; End; if (MyGetWindowsVersion='WIN7' ) OR (MyGetWindowsVersion='VISTA' ) OR (MyGetWindowsVersion='WIN8' ) then //或者 (Version.Major=6) begin if IsDotNetDetected('v4.5', 0) or IsDotNetDetected('v4.5.1', 0) or IsDotNetDetected('v4.5.2', 0) or IsDotNetDetected('v4.6', 0) or IsDotNetDetected('v4.6.1', 0) or IsDotNetDetected('v4.6.2', 0) or IsDotNetDetected('v4.7', 0) or IsDotNetDetected('v4.7.1', 0) or IsDotNetDetected('v4.7.2', 0) then begin Result :=true; End Else begin if MsgBox('系統檢測到您沒有安裝.Net Framework 4.5-4.7.2版本,是否立刻下載并安裝?', mbConfirmation, MB_YESNO)=idYes then begin Path :=ExpandConstant('{pf}/Internet Explorer/iexplore.exe'); //4.5.2 Exec(Path, 'http://download.microsoft.com/download/B/4/1/B4119C11-0423-477B-80EE-7A474314B347/NDP452-KB2901954-Web.exe', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode); MsgBox('請安裝好.Net Framework環境后(4.5-4.7.2),再運行本安裝包程序!',mbInformation,MB_OK); Result :=false; Exit; End Else begin MsgBox('沒有安裝.Net Framework環境,無法運行程序,本安裝程序即將退出!',mbInformation,MB_OK); Result :=false; Exit; end; end; end else begin Result :=true; End; if (MyGetWindowsVersion='10' ) then //或者 (Version.Major=10) begin if IsDotNetDetected('v4.6.1', 0) or IsDotNetDetected('v4.6.2', 0) or IsDotNetDetected('v4.7', 0) or IsDotNetDetected('v4.7.1', 0) or IsDotNetDetected('v4.7.2', 0) then begin Result :=true; End Else begin if MsgBox('系統檢測到您沒有安裝.Net Framework 4.6.1-4.8版本,是否立刻下載并安裝?', mbConfirmation, MB_YESNO)=idYes then begin Path :=ExpandConstant('{pf}/Internet Explorer/iexplore.exe'); //4.6.2 Exec(Path, 'http://download.microsoft.com/download/D/5/C/D5C98AB0-35CC-45D9-9BA5-B18256BA2AE6/NDP462-KB3151802-Web.exe', '', SW_SHOWNORMAL, ewWaitUntilTerminated, ResultCode); MsgBox('請安裝好.Net Framework環境后(4.6.1-4.8),再運行本安裝包程序!',mbInformation,MB_OK); Result :=false; Exit; End Else begin MsgBox('沒有安裝.Net Framework環境,無法運行程序,本安裝程序即將退出!',mbInformation,MB_OK); Result :=false; Exit; end; end; end else begin Result :=true; End; end;
.NET Framework 3.5是許多應用程序賴以運行的基礎環境框架,可謂是Windows系統必裝組件,可是有許多用戶卻遇到錯誤提示“Windows無法完成請求的更改。參數錯誤。錯誤代碼: 0x80070057”在線安裝失敗的問題。為此MS酋長早就已經分享了Win10離線安裝.NET Framework 3.5的方法和cab格式.NET Framework 3.5離線安裝包,但是這兩個方法都需要運行一句dism命令,小白用戶表示有難度,而且屢發錯誤安裝失敗等問題。所以今天MS酋長再分享一個借助Dism++離線安裝.NET Framework 3.5的方法,無需輸入任何命令即可完成。
PS: 其實MS酋長之前就已經介紹過Dism++徹底刪除驅動程序和使用Dism++把ESD轉換為ISO鏡像,這是因為Dism++是一款功能十分強大的系統工具,今天要介紹的離線安裝.NET Framework 3.5也只是它其中的一個小功能而已。
一、下載Win10 ISO鏡像
這個不用考慮版本,基本上都含有.NET Framework 3.5安全程序。下載Win10 ISO鏡像的途徑有很多,如果想保險,可以考慮到微軟官方網站下載Windows 10光盤映像( ISO 文件)。
二、下載Dism++
最新版Dism++下載地址:官方網站(點擊本文底部的“了解更多”查看原文可看到官網鏈接)
解壓之后,可以看到其中包括x86、x64和ARM64三個程序文件,分別對應32位、64位和ARM版Windows10系統。
三、裝載Win10 ISO鏡像
在下載好的Win10 ISO鏡像上點擊右鍵,選擇“裝載”。如圖:
Windows10系統即可加載該ISO鏡像,MS酋長這臺電腦顯示虛擬光驅盤符為 I 。如圖:
PS: 這是因為Win10自帶虛擬光驅功能,所以可以直接掛載ISO鏡像。
MS酋長的是64位Win10系統,所以就運行Dism++x64.exe 。在窗口左側的導航窗格中定位至“控制面板 - 程序和功能”,然后在右側主窗格中切換到“Windows功能”標簽。如圖:
在可選功能列表中找到.NET Framework 3.5(包括.NET 2.0和3.0 ),在選擇框中點擊一下,顯示為“部分啟用”即可。
Dism++窗口最右側的“本地源”則已經自動定位至Win10 ISO鏡像的 I:\sources\sxs 目錄。
點擊右下角的“應用”按鈕,窗口頂部就會顯示有“正在應用”進度條。如圖:
待應用完成后,會重新顯示“準備就緒”,這時候.NET Framework 3.5已經安裝完成了。
使用Win10任務欄中的搜索功能搜索“啟用或關閉Windows功能”打開“Windows功能”窗口。如圖:
如果看到其中的.NET Framework 3.5(包括.NET 2.0和3.0 )復選框已經顯示為部分選中狀態,說明已經成功安裝.NET Framework 3.5了。