Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Something like this should do it. Just grab the value from the registry</p> <p><strong>For .NET 1-4</strong>:</p> <p><code>Framework</code> is the highest installed version, <code>SP</code> is the service pack for that version.</p> <pre><code>RegistryKey installed_versions = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP"); string[] version_names = installed_versions.GetSubKeyNames(); //version names start with 'v', eg, 'v3.5' which needs to be trimmed off before conversion double Framework = Convert.ToDouble(version_names[version_names.Length - 1].Remove(0, 1), CultureInfo.InvariantCulture); int SP = Convert.ToInt32(installed_versions.OpenSubKey(version_names[version_names.Length - 1]).GetValue("SP", 0)); </code></pre> <p><strong>For .NET 4.5+</strong> (from <a href="https://msdn.microsoft.com/en-us/library/hh925568" rel="nofollow noreferrer">official documentation</a>):</p> <pre><code>using System; using Microsoft.Win32; ... private static void Get45or451FromRegistry() { using (RegistryKey ndpKey = RegistryKey.OpenBaseKey(RegistryHive.LocalMachine, RegistryView.Registry32).OpenSubKey("SOFTWARE\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full\\")) { int releaseKey = Convert.ToInt32(ndpKey.GetValue("Release")); if (true) { Console.WriteLine("Version: " + CheckFor45DotVersion(releaseKey)); } } } ... // Checking the version using &gt;= will enable forward compatibility, // however you should always compile your code on newer versions of // the framework to ensure your app works the same. private static string CheckFor45DotVersion(int releaseKey) { if (releaseKey &gt;= 461808) { return "4.7.2 or later"; } if (releaseKey &gt;= 461308) { return "4.7.1 or later"; } if (releaseKey &gt;= 460798) { return "4.7 or later"; } if (releaseKey &gt;= 394802) { return "4.6.2 or later"; } if (releaseKey &gt;= 394254) { return "4.6.1 or later"; } if (releaseKey &gt;= 393295) { return "4.6 or later"; } if (releaseKey &gt;= 393273) { return "4.6 RC or later"; } if ((releaseKey &gt;= 379893)) { return "4.5.2 or later"; } if ((releaseKey &gt;= 378675)) { return "4.5.1 or later"; } if ((releaseKey &gt;= 378389)) { return "4.5 or later"; } // This line should never execute. A non-null release key should mean // that 4.5 or later is installed. return "No 4.5 or later version detected"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload