Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect and require a Windows QFE/patch for during installation

Our WiX installer deploys a .NET 4.0 WinForms application to Windows Vista and 7 desktops. The application includes a Portable Class Library that requires a .NET patch (KB2468871). We need to install the patch as a prerequisite. There are various ways that the patch can be applied:

  1. Download the KB2468871 patch and install it
  2. Install the Portable Library Tools
  3. As a prerequisite using ClickOnce (might be a variation of #1)

Using advice from a similar question, I created a CustomAction to check for the QFE (#1) that I demonstrated returns true when found.

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;
}

Unfortunately, this fails on my dev machine as the patch was installed as part of the Tools (#2). I haven't witnessed situation #3 yet.

What is a better way to detect if the patch has been applied?

like image 640
Ed Chapel Avatar asked Feb 28 '12 07:02

Ed Chapel


People also ask

How to check Server Patching?

View the updates installed on your Server Core serverTo view updates by using Windows PowerShell, run Get-Hotfix. To view updates by running a command, run systeminfo.exe. There might be a short delay while the tool inspects your system. You can also run wmic qfe list from the command line.

How do I check for a patch update?

If you're connected the internet, try to install the updates manually. Select Start > Settings > Update & Security > Windows Update , and then select Check for updates.

How do I search for a specific Windows Update?

To check if a specific update is applied, follow these steps: Open Start menu. Go to Settings. Navigate to Update & Security > Windows Update.


1 Answers

Win32_QuickFixEngineering won't return all updates. Actually, it returns only updates restricted to QFE:

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

The update you're after is an MSI patch. Use Microsoft.Deployment.WindowsInstaller (aka DTF - Deployment Tools Foundation, part of the WiX toolset) to query the applied MSI patches:

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);
}

In this case, KB2468871 is one of .NET Framework 4 updates. The following will return true if the updates have been applied on the machine:

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
like image 101
KMoraz Avatar answered Oct 06 '22 16:10

KMoraz