gpt4 book ai didi

c# - 在安装期间检测并需要 Windows QFE/补丁

转载 作者:可可西里 更新时间:2023-11-01 12:24:57 24 4
gpt4 key购买 nike

我们的 WiX 安装程序将 .NET 4.0 WinForms 应用程序部署到 Windows Vista 和 7 桌面。该应用程序包括一个 Portable Class Library这需要 .NET patch (KB2468871)。我们需要安装补丁作为先决条件。可以通过多种方式应用补丁:

  1. 下载KB2468871补丁并安装
  2. 安装 Portable Library Tools
  3. 作为使用 ClickOnce 的先决条件(可能是 #1 的变体)

使用来自 a similar question 的建议,我创建了一个 CustomAction 来检查我演示的 QFE (#1) 在找到时返回 true。

private static bool IsPatchAlreadyInstalled()
{
// If the patch is installed, we can find it using WMI
var query = new SelectQuery("SELECT HotFixID FROM Win32_QuickFixEngineering WHERE HotFixID = 'Q2468871' OR HotFixID = 'KB2468871'");
var results = new ManagementObjectSearcher(query).Get();
return results.Count > 0;
}

不幸的是,这在我的开发机器上失败了,因为补丁是作为工具 (#2) 的一部分安装的。我还没有目睹情况 #3。

检测补丁是否已应用的更好方法是什么?

最佳答案

Win32_QuickFixEngineering不会返回所有更新。实际上,它只返回仅限于 QFE 的更新:

Updates supplied by Microsoft Windows Installer (MSI) or the Windows update site (http://update.microsoft.com) are not returned by Win32_QuickFixEngineering.

您要进行的更新是 MSI 补丁。使用 Microsoft.Deployment.WindowsInstaller(又名 DTF - Deployment Tools FoundationWiX toolset 的一部分)查询应用的 MSI 补丁:

public static bool IsPatchAlreadyInstalled(string productCode, string patchCode)
{
var patches =
PatchInstallation.GetPatches(null, productCode, null, UserContexts.Machine, PatchStates.Applied);

return patches.Any(patch => patch.DisplayName == patchCode);
}

在这种情况下,KB2468871 是 .NET Framework 4 更新之一。如果已在计算机上应用更新,则以下内容将返回 true:

IsPatchAlreadyInstalled("{F5B09CFD-F0B2-36AF-8DF4-1DF6B63FC7B4}", "KB2468871");// .NET Framework 4 Client Profile 64-bit
IsPatchAlreadyInstalled("{8E34682C-8118-31F1-BC4C-98CD9675E1C2}", "KB2468871");// .NET Framework 4 Extended 64-bit
IsPatchAlreadyInstalled("{3C3901C5-3455-3E0A-A214-0B093A5070A6}", "KB2468871");// .NET Framework 4 Client Profile 32-bit
IsPatchAlreadyInstalled("{0A0CADCF-78DA-33C4-A350-CD51849B9702}", "KB2468871");// .NET Framework 4 Extended 32-bit

关于c# - 在安装期间检测并需要 Windows QFE/补丁,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9478014/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com