How to Check Dot Net Version Installed on the PC
This code checks the dot net version installed on the PC.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Win32;
using System.Windows.Forms;
namespace BusinessLayer
{
class CheckVersion
{
public void Version(ListBox lbInstVersions)
{
string componentsKeyName = "SOFTWARE\\Microsoft\\Active Setup\\Installed Components",friendlyName,version;
// Find out in the registry anything under:
// HKLM\SOFTWARE\Microsoft\Active Setup\Installed Components
// that has ".NET Framework" in the name
RegistryKey componentsKey = Registry.LocalMachine.OpenSubKey(componentsKeyName);
string[] instComps = componentsKey.GetSubKeyNames();
foreach (string instComp in instComps)
{
RegistryKey key = componentsKey.OpenSubKey(instComp);
friendlyName = (string)key.GetValue(null); // Gets the (Default) value from this key
if (friendlyName != null && friendlyName.IndexOf(".NET Framework") >= 0)
{
// Let's try to get any version information that's available
version = (string)key.GetValue("Version");
// If you want only the framework info with its SP level and not the
// other hotfix and service pack detail, uncomment this if:
//if (version != null && version.Split(',').Length >= 4)
//{
// if(version[0].ToString()=="2")
lbInstVersions.Items.Add(friendlyName + (version != null ? (" (" + version + ")") : ""));
//}
}
}
}
}
}