The internets know many answers to the question how to get a list of all installed versions of the .Net Framework. (Hint: registry path HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP)![]()
Looking for some kind of “official” confirmation, I finally found this article in the MS Knowledge Base, How to determine which versions and service pack levels of the Microsoft .NET Framework are installed.
Converting this information into code
- Open the registry key and loop through its subkeys
static void Main(string[] args)
{
Console.WriteLine(".Net Framework Versions");
var hkNDP = Registry.LocalMachine.OpenSubKey(
@"SOFTWARE\Microsoft\NET Framework Setup\NDP", false);
WriteKey(hkNDP, "");
hkNDP.Close();
Console.ReadLine();
}
- For the subkeys, detect Version, SP, and Install values, and loop through subkeys
static void WriteKey(RegistryKey hk, string relPath)
{
if (relPath != "")
relPath += "/";
foreach (var keyname in hk.GetSubKeyNames())
{
var key = hk.OpenSubKey(keyname, false);
var keySP = key.GetValue("SP");
var keyVersion = key.GetValue("Version");
if (keyVersion != null)
Console.WriteLine(relPath + keyname +
": Version " + keyVersion.ToString() +
((keySP != null) ? " SP " + keySP.ToString() : "") +
(1.Equals(key.GetValue("Install")) ? " installed" : ""));
WriteKey(key, relPath + keyname);
key.Close();
}
}
On Windows 7 (German), this results in the following output
.Net Framework Versions v2.0.50727: Version 2.0.50727.4927 SP 2 installed v2.0.50727/1031: Version 2.0.50727.4927 SP 2 installed v3.0: Version 3.0.30729.4926 SP 2 installed v3.0/Setup: Version 3.0.30729.4926 v3.0/Setup/1031: Version 3.0.30729.4926 SP 2 installed v3.0/Setup/Windows Communication Foundation: Version 3.0.4506.4926 v3.0/Setup/Windows Presentation Foundation: Version 3.0.6920.4902 v3.5: Version 3.5.30729.4926 SP 1 installed v3.5/1031: Version 3.5.30729.4926 SP 1 installed v4/Client: Version 4.0.30319 installed v4/Client/1033: Version 4.0.30319 installed v4/Full: Version 4.0.30319 installed v4/Full/1033: Version 4.0.30319 installed
Advertisement

[...] The command netver lists all installed versions of the .Net framework. [...]