How to detect whether the machine have .Net Framework 3.5 install
from framework 2.0
from framework 2.0
public static ICollection<Version> GetInstalled_DotNet_Versions() {
List<Version> installedVersions = new List<Version>();
string componentsKeyName = @"SOFTWARE\Microsoft\NET Framework Setup\NDP";
string version;
int installedFlag;
try {
Microsoft.Win32.RegistryKey componentsKey = Microsoft.Win32.Registry.LocalMachine.OpenSubKey(componentsKeyName);
string[] subkeys = componentsKey.GetSubKeyNames();
foreach (string skey in subkeys) {
Microsoft.Win32.RegistryKey key = componentsKey.OpenSubKey(skey);
// Let's try to get any version information that's available
version = (string)key.GetValue("Version");
installedFlag = (int)key.GetValue("Install");
if (installedFlag > 0)
installedVersions.Add(new Version(version));
}
}
catch (Exception e) {
}
return installedVersions;
}
public static string GetMaxInstalled_DotNet_Version() {
ICollection<Version> versions = GetInstalled_DotNet_Versions();
Version maxVersion = new Version();
foreach (Version v in versions) {
if (v.CompareTo(maxVersion) > 0)
maxVersion = v;
}
return maxVersion.ToString();
}
Comment