A similar question was asked here, but it was specific to .NET 3.5. Specifically, I\'m looking for the following:
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.
I wanted to detect for the presence of .NET version 4.5.2 installed on my system, and I found no better solution than ASoft .NET Version Detector.
Snapshot of this tool showing different .NET versions:
In Windows 7 (it should work for Windows 8 also, but I haven't tested it):
Go to a command prompt
Steps to go to a command prompt:
In cmd, type this command
wmic /namespace:\\root\cimv2 path win32_product where "name like '%%.NET%%'" get version
This gives the latest version of NET Framework installed.
One can also try Raymond.cc Utilties for the same.
The Framework 4 beta installs to a differing registry key.
using System;
using System.Collections.ObjectModel;
using Microsoft.Win32;
class Program
{
static void Main(string[] args)
{
foreach(Version ver in InstalledDotNetVersions())
Console.WriteLine(ver);
Console.ReadKey();
}
public static Collection<Version> InstalledDotNetVersions()
{
Collection<Version> versions = new Collection<Version>();
RegistryKey NDPKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP");
if (NDPKey != null)
{
string[] subkeys = NDPKey.GetSubKeyNames();
foreach (string subkey in subkeys)
{
GetDotNetVersion(NDPKey.OpenSubKey(subkey), subkey, versions);
GetDotNetVersion(NDPKey.OpenSubKey(subkey).OpenSubKey("Client"), subkey, versions);
GetDotNetVersion(NDPKey.OpenSubKey(subkey).OpenSubKey("Full"), subkey, versions);
}
}
return versions;
}
private static void GetDotNetVersion(RegistryKey parentKey, string subVersionName, Collection<Version> versions)
{
if (parentKey != null)
{
string installed = Convert.ToString(parentKey.GetValue("Install"));
if (installed == "1")
{
string version = Convert.ToString(parentKey.GetValue("Version"));
if (string.IsNullOrEmpty(version))
{
if (subVersionName.StartsWith("v"))
version = subVersionName.Substring(1);
else
version = subVersionName;
}
Version ver = new Version(version);
if (!versions.Contains(ver))
versions.Add(ver);
}
}
}
}
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:
v2.0.50727 2.0.50727.4016 SP2
v3.0 3.0.30729.4037 SP2
v3.5 3.5.30729.01 SP1
v4
Client 4.0.30319
Full 4.0.30319
Note that for "versions 4.5 and later" there is another function.