Aaron Stebner's WebLog

Thoughts about setup and deployment issues, WiX, XNA, the .NET Framework and Visual Studio

Updated sample code to detect the .NET Framework 3.0

Updated sample code to detect the .NET Framework 3.0

  • Comments 1

I've received a few questions recently about how to programmatically detect whether or not the .NET Framework 3.0 is installed on a system.  As a result, I decided to update the sample code I previously published (here and here) to include logic to detect the .NET Framework 3.0 in addition to the previous logic for .NET 1.0, 1.1 and 2.0.

Where to download the sample code

You can find the updated sample code at the following locations:

Detection logic used in the sample code

The new code that I added to the above samples to check for the presence of the .NET Framework 3.0 searches for the following registry value (as described in the .NET Framework 3.0 deployment guide):

[HKEY_LOCAL_MACHINE\Software\Microsoft\NET Framework Setup\NDP\v3.0\Setup]
InstallSuccess=1

Detecting pre-release builds of the .NET Framework 3.0

However, we have seen some false positives if an application only searches for this registry value because this value is set in pre-release builds of the .NET Framework 3.0 in addition to the final release version.  In order to narrow down the detection even further and exclude pre-release builds, I added logic to the sample code that also looks at the following registry value:

[HKEY_LOCAL_MACHINE\Software\Microsoft\NET Framework Setup\NDP\v3.0\Setup]
Version

This Version value contains REG_SZ data that represents a 4-part version string of the form #.#.#####.##.  The final release version of the .NET Framework 3.0 contains the following version value:

  • On Windows Vista - 3.0.04506.26
  • On downlevel operating systems - 3.0.04506.30

The updated sample code contains a function named CheckNetfx30BuildNumber that contains the following logic:

  1. Attempt to read the Version registry value
  2. If the value is found, split the string into 4 parts using a period as a delimiter
  3. Convert each part of the string into integers
  4. Compare against the final release version number values
  5. If the value stored in the registry is greater than or equal to the final release version number, return true
  6. If any of the above fail, return false

This additional version validation is not "officially" documented anywhere, but is useful to provide a safeguard if you would like to prevent your application from installing on a system that has a pre-release build of the .NET Framework 3.0 installed.

As always, please let me know if you have any trouble building or running these samples or incorporating them into your product setup logic.

Leave a Comment
  • Please add 2 and 1 and type the answer here:
  • Post