297

A similar question was asked here, but it was specific to .NET 3.5. Specifically, I'm looking for the following:

  1. What is the correct way to determine which .NET Framework versions and service packs are installed?
  2. Is there a list of registry keys that can be used?
  3. Are there any dependencies between Framework versions?
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Scott Dorman
  • 42,236
  • 12
  • 79
  • 110
  • 2
    This question is closely related to http://stackoverflow.com/questions/198931/how-do-i-tell-if-net-35-sp1-is-installed and http://stackoverflow.com/questions/182910/determine-highest-net-framework-version – Pascal Paradis Oct 14 '08 at 02:18
  • Yes, it is. I already knew about the first one (it's the one I refer to in my question). I didn't know about the other one. – Scott Dorman Oct 14 '08 at 02:21
  • 3
    I'm impressed how this question (including answers) and all the closely related questions entirely ignore the presence of the [SKU values](http://stackoverflow.com/a/8066145/442376) -- this even differentiates between 4.5 and 4.5.1. – springy76 Mar 24 '14 at 11:39
  • @springy76, The reason this doesn't address the presence of SKU values is because, for the purposes of determining which versions of the Framework are installed, they aren't relevant. The question you refer to is actually trying to determine if ".NET 4.0.2" is installed. The problem here is that there was no .NET 4.0.2, it was an update (KB2544514), not a Framework release or a service pack. You can look at this article on MSDN (http://msdn.microsoft.com/en-us/library/hh925567(v=vs.110).aspx) for more information on how to detect which updates are installed. – Scott Dorman Mar 24 '14 at 13:53
  • Here you have [Check which version of .net ...](http://www.askvg.com/how-to-check-which-version-of-microsoft-net-framework-is-installed-in-windows/) – DanielV Aug 20 '15 at 10:38
  • MS provided a PowerShell Script to list all of the .NET Framework versions and their service pack: [How to determine versions & service pack levels of .NET Framework by PowerShell](https://gallery.technet.microsoft.com/How-to-determine-versions-d3669799) – Dale Chen Sep 07 '16 at 08:08

13 Answers13

372

The registry is the official way to detect if a specific version of the Framework is installed.

enter image description here

Which registry keys are needed change depending on the Framework version you are looking for:

Framework Version  Registry Key
------------------------------------------------------------------------------------------
1.0                HKLM\Software\Microsoft\.NETFramework\Policy\v1.0\3705 
1.1                HKLM\Software\Microsoft\NET Framework Setup\NDP\v1.1.4322\Install 
2.0                HKLM\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727\Install 
3.0                HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.0\Setup\InstallSuccess 
3.5                HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.5\Install 
4.0 Client Profile HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Client\Install
4.0 Full Profile   HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Full\Install

Generally you are looking for:

"Install"=dword:00000001

except for .NET 1.0, where the value is a string (REG_SZ) rather than a number (REG_DWORD).

Determining the service pack level follows a similar pattern:

Framework Version  Registry Key
------------------------------------------------------------------------------------------
1.0                HKLM\Software\Microsoft\Active Setup\Installed Components\{78705f0d-e8db-4b2d-8193-982bdda15ecd}\Version 
1.0[1]             HKLM\Software\Microsoft\Active Setup\Installed Components\{FDC11A6F-17D1-48f9-9EA3-9051954BAA24}\Version 
1.1                HKLM\Software\Microsoft\NET Framework Setup\NDP\v1.1.4322\SP 
2.0                HKLM\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727\SP 
3.0                HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.0\SP 
3.5                HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.5\SP 
4.0 Client Profile HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Client\Servicing
4.0 Full Profile   HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Full\Servicing

[1] Windows Media Center or Windows XP Tablet Edition

As you can see, determining the SP level for .NET 1.0 changes if you are running on Windows Media Center or Windows XP Tablet Edition. Again, .NET 1.0 uses a string value while all of the others use a DWORD.

For .NET 1.0 the string value at either of these keys has a format of #,#,####,#. The last # is the Service Pack level.

While I didn't explicitly ask for this, if you want to know the exact version number of the Framework you would use these registry keys:

Framework Version  Registry Key
------------------------------------------------------------------------------------------
1.0                HKLM\Software\Microsoft\Active Setup\Installed Components\{78705f0d-e8db-4b2d-8193-982bdda15ecd}\Version 
1.0[1]             HKLM\Software\Microsoft\Active Setup\Installed Components\{FDC11A6F-17D1-48f9-9EA3-9051954BAA24}\Version 
1.1                HKLM\Software\Microsoft\NET Framework Setup\NDP\v1.1.4322 
2.0[2]             HKLM\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727\Version 
2.0[3]             HKLM\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727\Increment
3.0                HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.0\Version 
3.5                HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.5\Version 
4.0 Client Profile HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Version 
4.0 Full Profile   HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Version 

[1] Windows Media Center or Windows XP Tablet Edition
[2] .NET 2.0 SP1
[3] .NET 2.0 Original Release (RTM)

Again, .NET 1.0 uses a string value while all of the others use a DWORD.

Additional Notes

  • for .NET 1.0 the string value at either of these keys has a format of #,#,####,#. The #,#,#### portion of the string is the Framework version.

  • for .NET 1.1, we use the name of the registry key itself, which represents the version number.

  • Finally, if you look at dependencies, .NET 3.0 adds additional functionality to .NET 2.0 so both .NET 2.0 and .NET 3.0 must both evaulate as being installed to correctly say that .NET 3.0 is installed. Likewise, .NET 3.5 adds additional functionality to .NET 2.0 and .NET 3.0, so .NET 2.0, .NET 3.0, and .NET 3. should all evaluate to being installed to correctly say that .NET 3.5 is installed.

  • .NET 4.0 installs a new version of the CLR (CLR version 4.0) which can run side-by-side with CLR 2.0.

Update for .NET 4.5

There won't be a v4.5 key in the registry if .NET 4.5 is installed. Instead you have to check if the HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Full key contains a value called Release. If this value is present, .NET 4.5 is installed, otherwise it is not. More details can be found here and here.

Martin Schneider
  • 14,263
  • 7
  • 55
  • 58
Scott Dorman
  • 42,236
  • 12
  • 79
  • 110
  • 1
    This doesn't appear to work for .NET 1.1 under Vista x64. No v1.1.x keys are in any of the possible places. Ideas? – Chris Hynes May 11 '09 at 21:04
  • 8
    The keys for .NET 4.0 are not quite correct. I'm seeing these keys: HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Client\Install HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Full\Install The v4.0 folder only has one key, (Default) with a value of deprecated. – RandomEngy Apr 10 '10 at 01:37
  • 1
    @RandomEngy: You're correct. The registry keys should have been "v4" not "v4.0". I corrected the post. – Scott Dorman Apr 16 '10 at 00:27
  • Minor typo: 4.0 Full Profile HKLM\Softwaer\Microsoft\NET Framework Setup\NDP\v4\Full\Servicing I copied it and had some issues! Software has a typo on this key. – Nate Zaugg May 27 '10 at 16:36
  • There appears to be a client profile for 3.5 as well - how can I tell which I have installed? – bdonlan Jun 28 '11 at 15:53
  • 2
    This post doesn't cover 4.5, and 4.5 is not listed in the registry even though it is installed. – Klas Mellbourn Nov 15 '12 at 14:07
  • @ChrisHynes - That's registry virtualization. They are present only in the 32bit registry. .NET 1.x are the only framework versions where you need to care about this. – Jirka Hanika Jul 04 '13 at 17:13
  • 41
    Man, did no-one at Microsoft think to add a -version switch? – gnuchu Sep 13 '13 at 12:58
  • I found this helpful clarification for detecting 4.5.1 http://blogs.msdn.com/b/astebner/archive/2013/11/11/10466402.aspx [link](http://blogs.msdn.com/b/astebner/archive/2013/11/11/10466402.aspx) –  Mar 03 '14 at 11:29
  • @gnuchu, A -version switch would only tell you the version of the Framework which is currently running. This can tell you *all* of the versions installed, not just the one running. – Scott Dorman Mar 24 '14 at 15:23
  • @ConradB, Aaron's blog posts about version detection are great and were used as the basis for a lot of the research for the initial answer. – Scott Dorman Mar 24 '14 at 15:25
  • 1
    I have .net 4.5.X installed but i have no key named `HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Full` or `HKLM\Software\Wow6432Node\Microsoft\NET Framework Setup\NDP\v4\Full`.. – Peter Nov 27 '14 at 07:27
  • Please note the difference between the "Full" and the "Client" key: If the user has uninstalled ".NET Framework 4 Extended" in Control Panel, only the "Client" key will remain and several assemblies will be missing like System.Web, System.Design, System.Workflow, System.ServiceModel, System.Data.OracleClient, Microsoft.Build and others – Elmue Nov 02 '15 at 15:07
  • [here](http://stackoverflow.com/a/14482427/2218697) is another option **using command prompt** – Shaiju T Mar 13 '16 at 07:38
  • 1
    @storm: That will tell you the most current version installed, but it won't list service packs and can't tell you all of the different versions that might be installed. – Scott Dorman Mar 14 '16 at 16:13
  • 3
    It's a joke. I can't believe it is sooooo dumb! – Alex Byrth Aug 10 '16 at 13:31
  • If it has never installed, this method works. But what if somebody deliberately uninstalled the net fx? the registry still exists but the framework is gone. This method does not seem to be able to detect that. – Fandi Susanto Oct 10 '16 at 04:11
  • I am dumbfounded at how ridiculous this is, over decades of Visual Studio and we resort to this?? My gosh. – JREAM Sep 01 '17 at 21:14
  • and for latests NET Framework versions 4.7.2 and 4.8 ? – Kiquenet Aug 23 '22 at 08:24
18

There is an official Microsoft answer to this question at the following knowledge base article:

Article ID: 318785 - Last Review: November 7, 2008 - Revision: 20.1 How to determine which versions of the .NET Framework are installed and whether service packs have been applied

Unfortunately, it doesn't appear to work, because the mscorlib.dll version in the 2.0 directory has a 2.0 version, and there is no mscorlib.dll version in either the 3.0 or 3.5 directories even though 3.5 SP1 is installed ... why would the official Microsoft answer be so misinformed?

abatishchev
  • 98,240
  • 88
  • 296
  • 433
anon
  • 189
  • 1
  • 2
17

The Framework 4 beta installs to a differing registry key.

using System;
using System.Collections.ObjectModel;
using Microsoft.Win32;

class Program
{
    static void Main(string[] args)
    {
        foreach(Version ver in InstalledDotNetVersions())
            Console.WriteLine(ver);

        Console.ReadKey();
    }


    public static Collection<Version> InstalledDotNetVersions()
    {
        Collection<Version> versions = new Collection<Version>();
        RegistryKey NDPKey = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP");
        if (NDPKey != null)
        {
            string[] subkeys = NDPKey.GetSubKeyNames();
            foreach (string subkey in subkeys)
            {
                GetDotNetVersion(NDPKey.OpenSubKey(subkey), subkey, versions);
                GetDotNetVersion(NDPKey.OpenSubKey(subkey).OpenSubKey("Client"), subkey, versions);
                GetDotNetVersion(NDPKey.OpenSubKey(subkey).OpenSubKey("Full"), subkey, versions);
            }
        }
        return versions;
    }

    private static void GetDotNetVersion(RegistryKey parentKey, string subVersionName, Collection<Version> versions)
    {
        if (parentKey != null)
        {
            string installed = Convert.ToString(parentKey.GetValue("Install"));
            if (installed == "1")
            {
                string version = Convert.ToString(parentKey.GetValue("Version"));
                if (string.IsNullOrEmpty(version))
                {
                    if (subVersionName.StartsWith("v"))
                        version = subVersionName.Substring(1);
                    else
                        version = subVersionName;
                }

                Version ver = new Version(version);

                if (!versions.Contains(ver))
                    versions.Add(ver);
            }
        }
    }
}
midspace
  • 922
  • 9
  • 18
  • 2
    Change `Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP", true)` to `Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\NET Framework Setup\NDP")` to avoid a security exception on non-admin users. – Jon Cage Jan 24 '11 at 13:12
  • Cool, I used LinqPad and it gave me perfect results! http://share.linqpad.net/5cjihh.linq – user917170 Jan 09 '15 at 00:40
  • It is strange that you share about small details (like which service pack version is installed) but the more important information (if the the framework is installed only partially or completely) is ignored by your code!! It is wrong to treat the Registry Keys "Client" and "Full" as if they were the same. If only the "Client" key exits for example System.Web will not be available. This important information should also be returned by your code! If the user has uninstalled ".NET Framework 4 Extended" in Control Panel there will be several assemblies missing. – Elmue Nov 02 '15 at 14:59
9

I wanted to detect for the presence of .NET version 4.5.2 installed on my system, and I found no better solution than ASoft .NET Version Detector.

Snapshot of this tool showing different .NET versions:

Snapshot of this tool showing different .NET versions

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Faisal Mq
  • 5,036
  • 4
  • 35
  • 39
7

Enumerate the subkeys of HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP. Each subkey is a .NET version. It should have Install=1 value if it's present on the machine, an SP value that shows the service pack and an MSI=1 value if it was installed using an MSI. (.NET 2.0 on Windows Vista doesn't have the last one for example, as it is part of the OS.)

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Franci Penov
  • 74,861
  • 18
  • 132
  • 169
  • I didn't find this key on my machine (XP Pro), but I did have this: HKLM\SOFTWARE\Microsoft\.NETFramework. However, the various values you describe don't exist for me. – Charlie Oct 13 '08 at 21:41
  • You should have this key if you have .NET 1.1 or later installed. The key you mentioned was only used for .NET 1.0. – Scott Dorman Oct 14 '08 at 02:09
  • reg query "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\NET Framework Setup\NDP" – enthus1ast Mar 10 '15 at 19:45
5

Update for .NET 4.5.1

Now that .NET 4.5.1 is available the actual value of the key named Release in the registry needs to be checked, not just its existence. A value of 378758 means that .NET Framework 4.5.1 is installed. However, as described here this value is 378675 on Windows 8.1.

JasonMcF
  • 632
  • 8
  • 18
5

There is a GUI tool available, ASoft .NET Version Detector, which has always proven highly reliable. It can create XML files by specifying the file name of the XML output on the command line.

You could use this for automation. It is a tiny program, written in a non-.NET dependent language and does not require installation.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
CarlR
  • 1,718
  • 1
  • 17
  • 21
5

For a 64-bit OS, the path would be:

HKEY_LOCAL_MACHINE\SOFTWARE\wow6432Node\Microsoft\NET Framework Setup\NDP\
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
  • 10
    This is only "somewhat" true. The registry in 64-bit versions of Windows is divided into 32-bit and 64-bit keys (with many of the 32-bit keys having the same name as the 64-bit keys). The `Wow6432Node` registry key is part of the WOW64 registry reflector, which mirrors certain keys and values between the 64-bit and 32-bit registry views. There should be no need to access this key directly as the registry automatically handles the redirection and mirroring. – Scott Dorman May 11 '10 at 15:05
4

I was needing to find out just which version of .NET framework I had on my computer, and all I did was go to the control panel and select the "Uninstall a Program" option. After that, I sorted the programs by name, and found Microsoft .NET Framework 4 Client Profile.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Kudzai K
  • 41
  • 1
  • 1
    Thanks -- Every other "solution" I tried was flawed and wouldn't work. This did. – user20493 May 29 '12 at 17:39
  • 1
    The reason I came looking for this information was that the stuff under Uninstall a Program is totally unreliable, at least when it comes to .NET Framework. – tobbenb3 Oct 04 '13 at 09:47
3

Here is a PowerShell script to obtain installed .NET framework versions

function Get-KeyPropertyValue($key, $property)
{
    if($key.Property -contains $property)
    {
        Get-ItemProperty $key.PSPath -name $property | select -expand $property
    }
}

function Get-VersionName($key)
{
   $name = Get-KeyPropertyValue $key Version
   $sp = Get-KeyPropertyValue $key SP
   $install = Get-KeyPropertyValue $key Install
   if($sp)
   {
        "$($_.PSChildName) $name SP $sp"
   }
   else{
    "$($_.PSChildName) $name"
   }
}

function Get-FrameworkVersion{
   dir "hklm:\SOFTWARE\Microsoft\NET Framework Setup\NDP\" |? {$_.PSChildName -like "v*"} |%{
    if( $_.Property -contains "Version")
    {
        Get-VersionName $_
    }
    else{
        $parent = $_
        Get-ChildItem $_.PSPath |%{
            $versionName = Get-VersionName $_
            "$($parent.PSChildName) $versionName"
            }
        }
    }
}


$v4Directory = "hklm:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full"
if(Test-Path $v4Directory)
{
    $v4 = Get-Item $v4Directory
    $version = Get-KeyPropertyValue $v4 Release
    switch($version){
        378389 {".NET Framework 4.5"; break;}
        378675 {".NET Framework 4.5.1 installed with Windows 8.1 or Windows Server 2012 R2"; break;}
        378758 {".NET Framework 4.5.1 installed on Windows 8, Windows 7 SP1, or Windows Vista SP2"; break;}
        379893 {".NET Framework 4.5.2"; break;}
        { 393295, 393297 -contains $_} {".NET Framework 4.6"; break;}
        { 394254, 394271 -contains $_} {".NET Framework 4.6.1"; break;}
        { 394802, 394806 -contains $_} {".NET Framework 4.6.2"; break; }
    }
}

It was written based on How to: Determine Which .NET Framework Versions Are Installed. Please use THE Get-FrameworkVersion() function to get information about installed .NET framework versions.

henrycarteruk
  • 12,708
  • 2
  • 36
  • 40
cezarypiatek
  • 1,078
  • 11
  • 21
2

Using the Signum.Utilities library from SignumFramework (which you can use stand-alone), you can get it nicely and without dealing with the registry by yourself:

AboutTools.FrameworkVersions().ToConsole();
//Writes in my machine:
//v2.0.50727 SP2
//v3.0 SP2
//v3.5 SP1
Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
mapache
  • 1,361
  • 9
  • 11
  • 2
    Looking at the code for this method, it's not very complete as far as what registry keys it uses and will miss .NET 1.0 completely and doesn't distinguish between .NET 2.0 (RTM) and .NET 2.0 SP1. It also doesn't take into account the dependencies between framework versions. – Scott Dorman Mar 17 '09 at 19:10
  • 2
    Not a good solution. There's no good reason to download an entire library just to get the .NET version when you can do the same work yourself in about 3 lines of code. As a programmer, you SHOULD be able to "deal with the registry yourself." – TheSmurf May 21 '09 at 22:18
  • 3
    @DannySmurf I don't agree. When .NET 3.0 was introduced MS should have wrapped this in a .NET API (as soon as we had than one layer of FX on the same CLR). I'd rather have my application use a utility library, then when 4.1, 6.1, 7.100 arrives, I can just update the library and a config entry for which layer of .NET my app requires. Of course this argument doesn't hold water if none of the libraries work. – yzorg Jul 27 '10 at 21:08
1

See How to: Determine Which .NET Framework Versions Are Installed (MSDN).

MSDN proposes one function example that seems to do the job for version 1-4. According to the article, the method output is:

v2.0.50727  2.0.50727.4016  SP2
v3.0  3.0.30729.4037  SP2
v3.5  3.5.30729.01  SP1
v4
  Client  4.0.30319
  Full  4.0.30319

Note that for "versions 4.5 and later" there is another function.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Olivier de Rivoyre
  • 1,579
  • 1
  • 18
  • 24
1

In Windows 7 (it should work for Windows 8 also, but I haven't tested it):

Go to a command prompt

Steps to go to a command prompt:

  1. Click Start Menu
  2. In Search Box, type "cmd" (without quotes)
  3. Open cmd.exe

In cmd, type this command

wmic /namespace:\\root\cimv2 path win32_product where "name like '%%.NET%%'" get version

This gives the latest version of NET Framework installed.

One can also try Raymond.cc Utilties for the same.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Mayank Agarwal
  • 885
  • 1
  • 9
  • 7