Search code examples
wixwindows-installerwix3.8windows-update

WIX - Automatically detect and install MS KB patch


I am attempting to modify a WIX installer package so that it can detect the presence of a specific Microsoft Knowledge Base patch/update, and then offer the user a chance to download and install it on-the-fly if the patch is not detect. My order of operations would be:

  1. Detect if user is installing on Windows 8.1 or not (trivial, compare against VersionNT).
  2. Detect if KB 2883200 is already installed.
  3. If detected, provide a dialogue box offering the chance to download and install the package.

Steps 2 and 3 aren't 100% obvious to me. I've found a possible solution via another StackOverflow post, but I don't understand why both a hash and the KB number need to be provided. eg:

Sample Function


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

Use


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

So, the first part of my question would be: How can I use the code above to detect if the KB 2883200 patch is installed, and how do I generate the appropriate hash/UUID for the first argument passed to the function?

Next, I am trying to make a modal dialogue box appear, offering the user the chance to install the patch? If the user goes "Back" in the installer, I'd like the dialogue to re-appear when reaching the appropriate step again, in case they accidentally declined the offer to install the driver.

For the second and final part of my question: how do I provide such a dialogue box, and is there any existing method to download and install a MS KB patch through the installer, or do I have to implement my own methods from scratch?

Thank you.


Solution

  • The dialog box will be a dialog that you insert in the MSI UI sequence and show it if the update isn't installed, an publish the dialog with a condition. A potential issue with doing any of this in the UI sequence is that you won't be elevated, so if elevated privileges are required for this you may be in some difficulty.

    I think Tom's suggestion is the way to do this - make it a prerequisite for which you build you own executable to check for it, integrate that with Burn.

    Either way, to check for and install the update I'd use the Windows Update API. The update is available through Windows Update, and this kind of thing tells you if the update is applicable to a particular system and will also download it:

    https://msdn.microsoft.com/en-us/library/windows/desktop/aa387102(v=vs.85).aspx