// (Note that lbInstVersions is a listbox placed on a WinForm or Web Form.)
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)
lbInstVersions.Items.Add(friendlyName+(version!=null?(" ("+version+")"):""));
}
}