Thursday, August 1, 2013

.NET Framework Version (including 4.0+)

As the .NET Framework 4.5 is an in place update then it updates assemblies if .NET 4.0 is already installed, the best way to find out available .NET framework versions in the system would be checking it in registry.

The following code is executable directly in LinqPad too, you can get the perfect LinqPad tool (free) by (Joseph Albahari) here.

// Microsoft.Win32 // System void Main() { RegistryKey ndpKey = RegistryKey.OpenBaseKey( RegistryHive.LocalMachine , RegistryView.Registry32).OpenSubKey( @"SOFTWARE\Microsoft\NET Framework Setup\NDP\"); foreach (string verKeyName in ndpKey.GetSubKeyNames()) { if (verKeyName.StartsWith("v")) { RegistryKey verKey = ndpKey.OpenSubKey(verKeyName); string name = (string)verKey.GetValue("Version", ""); string sp = verKey.GetValue("SP", "").ToString(); string install = verKey.GetValue("Install", "").ToString(); if (install == "") Console.WriteLine( verKeyName + " " + name); else if (sp != "" && install == "1") Console.WriteLine( verKeyName + " " + name + " SP" + sp); if (name != "") continue; foreach (string subKeyName in verKey.GetSubKeyNames()) { RegistryKey subKey = verKey.OpenSubKey(subKeyName); name = (string)subKey.GetValue("Version", ""); if (name != "") sp = subKey.GetValue("SP", "").ToString(); install = subKey.GetValue("Install", "").ToString(); if (install == "") Console.WriteLine(verKeyName + " " + name); else if (sp != "" && install == "1") Console.WriteLine( " " + subKeyName + " " + name + " SP" + sp); else if (install == "1") Console.WriteLine( " " + subKeyName + " " + name); } } } }

Share/Bookmark

No comments: