Detecting Patches in .NET 2.0 and Visual Studio 2005

Heath Stewart

Aaron Stebnerpostedsome sample code to detect whether the .NET Framework 1.0, 1.1, or 2.0 wereinstalled and at what service pack level they are. Basically, the .NET Frameworkinstallation writes a common, version-specific registry key in the followinglocation along with an SP level registry value. The sample below for an English(United States) installation of .NET 2.0 is shown using the registry fileformat.

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftNET Framework SetupNDPv2.0.50727]

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftNET Framework SetupNDPv2.0.507271033]

To detect if service pack 1 is installed, check thatthe “SP” value is 1.

If you need to detect a specific hotfix patch you shouldnote the KB article number and follow the specific steps to determine if thehotfixis installed. Also note which SP level (including RTM) the hotfix targets.

  1. Check the service pack level as described above.
    • If the SP value in the registry is greater then the target SP level of the hotfix, the changes made by the hotfix are installed. Please note that there are rare exceptions to this rule. You are finished detecting for a specific patch.
    • If the SP value in the registry is equal to the target SP level of the hotfix, proceed with the following steps.
  2. Check for the KB article number under HKEY_LOCAL_MACHINESoftwareMicrosoftUpdates[ProductName], where [ProductName] is the value of the ProductName property in the Property table of the application set .msi file. Below is another sample registry format file for a patch targeting the release of .NET Framework 2.0. You would want to check that the value “Installed” in bold exists. The example is for a fictitious KB123446.

[HKEY_LOCAL_MACHINESOFTWAREMicrosoftUpdatesMicrosoft .NET Framework 2.0KB123456]
“UninstallCommand”=”C:\WINDOWS\system32\msiexec.exe /promptrestart /uninstall {633ECF8F-DAD3-4E23-AAD6-52D6386C9099} /package {7131646D-CD3C-40F4-97B9-CD9E4E6262EF}”
“PublishingGroup”=”Developer Division Customer Product-lifecycle Experience”
“Publisher”=”Microsoft Corporation”
“PackageName”=”Hotfix for Microsoft .NET Framework 2.0 (KB123456)”
“Description”=”This Hotfix is for Microsoft .NET Framework 2.0. \n
If you later install a more recent service pack, this Hotfix will be uninstalled automatically. \n
For more information, visit″
“InstalledBy”=”Heath Stewart”

When a new hotfix patch supersedes. or replaces, an older installed hotfix patch, the registrydetection keys described above will not be deleted. The superseding patch doesnot write the detection keys of superseded patches, however. This is a changefrom .NET Framework 1.0 and 1.1 but we are working to make patch detectioncommon throughout products from Microsoft and are pushing toward patch detection asprovided by Windows Installer for Windows Installer-installed patches.

If you rely on a fix within a certain file, you can also check the fileversion and compare the component parts of the dotted-quad version format. ForWindows Installer packages, you can use theDrLocator table, along with theSignature table and theAppSearch table to set a property if a file version is within a given rangeof version numbers. If you rely on theLaunchCondition table to check for the existence of the property to be setif the file exist within the given version range, make sure to schedule thestandardAppSearch action before the standardLaunchConditions action.