A similar question was asked here, but it was specific to .NET 3.5. Specifically, I'm looking for the following:
- What is the correct way to determine which .NET Framework versions and service packs are installed?
- Is there a list of registry keys that can be used?
- Are there any dependencies between Framework versions?
Enumerate the subkeys of
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP
. Each subkey is a .NET version. It should haveInstall=1
value if it's present on the machine, an SP value that shows the service pack and anMSI=1
value if it was installed using an MSI. (.NET 2.0 on Windows Vista doesn't have the last one for example, as it is part of the OS.)I was needing to find out just which version of .NET framework I had on my computer, and all I did was go to the control panel and select the "Uninstall a Program" option. After that, I sorted the programs by name, and found Microsoft .NET Framework 4 Client Profile.
See How to: Determine Which .NET Framework Versions Are Installed (MSDN).
MSDN proposes one function example that seems to do the job for version 1-4. According to the article, the method output is:
Note that for "versions 4.5 and later" there is another function.
The registry is the official way to detect if a specific version of the Framework is installed.
Which registry keys are needed change depending on the Framework version you are looking for:
Generally you are looking for:
except for .NET 1.0, where the value is a string (
REG_SZ
) rather than a number (REG_DWORD
).Determining the service pack level follows a similar pattern:
As you can see, determining the SP level for .NET 1.0 changes if you are running on Windows Media Center or Windows XP Tablet Edition. Again, .NET 1.0 uses a string value while all of the others use a DWORD.
For .NET 1.0 the string value at either of these keys has a format of #,#,####,#. The last # is the Service Pack level.
While I didn't explicitly ask for this, if you want to know the exact version number of the Framework you would use these registry keys:
Again, .NET 1.0 uses a string value while all of the others use a DWORD.
Additional Notes
for .NET 1.0 the string value at either of these keys has a format of
#,#,####,#
. The#,#,####
portion of the string is the Framework version.for .NET 1.1, we use the name of the registry key itself, which represents the version number.
Finally, if you look at dependencies, .NET 3.0 adds additional functionality to .NET 2.0 so both .NET 2.0 and .NET 3.0 must both evaulate as being installed to correctly say that .NET 3.0 is installed. Likewise, .NET 3.5 adds additional functionality to .NET 2.0 and .NET 3.0, so .NET 2.0, .NET 3.0, and .NET 3. should all evaluate to being installed to correctly say that .NET 3.5 is installed.
.NET 4.0 installs a new version of the CLR (CLR version 4.0) which can run side-by-side with CLR 2.0.
Update for .NET 4.5
There won't be a
v4.5
key in the registry if .NET 4.5 is installed. Instead you have to check if theHKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Full
key contains a value calledRelease
. If this value is present, .NET 4.5 is installed, otherwise it is not. More details can be found here and here.Update for .NET 4.5.1
Now that .NET 4.5.1 is available the actual value of the key named Release in the registry needs to be checked, not just its existence. A value of 378758 means that .NET Framework 4.5.1 is installed. However, as described here this value is 378675 on Windows 8.1.
The Framework 4 beta installs to a differing registry key.