wpf .net core win7 独立运行补丁安装记录
Windows 7 系统上,根据 dotnet 官方文档,需要安装上 KB2533623 补丁
方案如下:
首先使用 fx 2.0 写一个启动器 如果检测可以运行则拉起.net core 主程序 否则弹出命令行提示安装补丁
using PInvoke; using System; using System.Diagnostics; using System.Windows.Forms; namespace netcorefix { class Program { static void Main(string[] args) { using (var hModule = Kernel32.LoadLibrary("Kernel32.dll")) { if (!hModule.IsInvalid) { IntPtr hFarProc = Kernel32.GetProcAddress(hModule, "AddDllDirectory"); if (hFarProc != IntPtr.Zero) { Console.WriteLine("Either running on Win8+, or KB2533623 is installed"); } else { Console.Write("Likely running on Win7 or older OS, and KB2533623 is not installed"); Process proc = new Process(); proc.StartInfo.FileName = "installpack.bat"; proc.Start(); proc.WaitForExit(); MessageBox.Show("修补完成请重启电脑"); } } } // 以下是判断 Universal C Runtime 的逻辑,可以忽略 using (var hModule = Kernel32.LoadLibraryEx("UCRTBASE.dll", IntPtr.Zero, Kernel32.LoadLibraryExFlags.LOAD_LIBRARY_SEARCH_SYSTEM32)) { if (!hModule.IsInvalid) { Console.WriteLine("UCRT is available - Either running on Win10+ or KB2999226 is installed"); } else { Console.WriteLine("UCRT is not available - Likely running on OS older than Win10 and KB2999226 is not installed"); } } } } }
2、创建一个bat文件将以下命令复制到bat里 补丁放在同一个目录
echo 正在安装补丁请稍后.... cd /d %~dp0 wmic qfe GET hotfixid | findstr /C:"KB2533623" if %errorlevel% equ 0 (Echo Patch KB2533623 installed) else ( wusa Windows6.1-KB2533623-x64.msu /quiet /norestart wusa Windows6.1-KB2533623-x86.msu /quiet /norestart exit /b 1 ) exit /b 0
本文转自:https://blog.lindexi.com/post/%E6%8E%A2%E7%B4%A2-dotnet-core-%E4%B8%BA%E4%BD%95%E5%9C%A8-Windows7-%E7%B3%BB%E7%BB%9F%E9%9C%80%E8%A6%81%E8%A1%A5%E4%B8%81%E7%9A%84%E5%8E%9F%E5%9B%A0.html