How to detect what .NET Framework versions and service packs are installed?

quiverlickforkΛογισμικό & κατασκευή λογ/κού

2 Νοε 2013 (πριν από 3 χρόνια και 11 μήνες)

122 εμφανίσεις

How to detect what .NET Framework versions and service packs are insta... http://stackoverflow.com/questions/199080/how-to-detect-what-net-fram...
First time here? Check out the FAQ!
×
How to detect what .NET Framework versions and service packs are installed?
1 of 5 6/9/2010 7:11 AMHow to detect what .NET Framework versions and service packs are insta... http://stackoverflow.com/questions/199080/how-to-detect-what-net-fram...
First time here? Check out the FAQ!
×
A similar question was asked here, but 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?
.net framework installation version-detection
edited Oct 16 '09 at 16:52 asked Oct 13 '08 at 21:22
Peter Mortensen Scott Dorman
2,773 1 4 18 12.2k 1 17 42
67% accept rate
This question is closely related to stackoverflow.com/questions/198931/5 and stackoverflow.com/questions
/182910/5 – Pascal Paradis Oct 14 '08 at 2: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 2:21
8 Answers
The registry is the "official" way to detect if a specific version of the Framework is installed, but 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\Instal
3.0 HKLM\Software\Microsoft\NET Framework Setup\NDP\v3.0\Setup\Instal
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
The value is also different. For .NET 1.0, the value is a String value; all others use a DWORD.
Determining the service pack level follows a similar pattern:
Framework Version Registry Key
------------------------------------------------------------------------------------
1.0 HKLM\Software\Microsoft\Active Setup\Installed Components\{78705f
1.0[1] HKLM\Software\Microsoft\Active Setup\Installed Components\{FDC11A
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\Servici
4.0 Full Profile HKLM\Softwaer\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:
2 of 5 6/9/2010 7:11 AMHow to detect what .NET Framework versions and service packs are insta... http://stackoverflow.com/questions/199080/how-to-detect-what-net-fram...
First time here? Check out the FAQ!
×
------------------------------------------------------------------------------------
1.0 HKLM\Software\Microsoft\Active Setup\Installed Components\{78705f
1.0[1] HKLM\Software\Microsoft\Active Setup\Installed Components\{FDC11A
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\Versio
2.0[3] HKLM\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727\Increm
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.
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.
edited Apr 16 at 0:26 answered Oct 14 '08 at 2:04
Scott Dorman
12.2k 1 17 42
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
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 at 1:37
@RandomEngy: You're correct. The registry keys should have been "v4" not "v4.0". I corrected the post.
– Scott Dorman Apr 16 at 0: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 at 16:36
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 Vista doesn't
have the last one for example, as it is part of the OS)
answered Oct 13 '08 at 21:37
Franci Penov
18.6k 3 26 49
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 2:09
Small correction for the .NET 4 keys. They are actually here for RTM:
3 of 5 6/9/2010 7:11 AMHow to detect what .NET Framework versions and service packs are insta... http://stackoverflow.com/questions/199080/how-to-detect-what-net-fram...
First time here? Check out the FAQ!
×
Not in v4.0.
answered Apr 12 at 21:04
RandomEngy
1,275 1 13
Correct. I updated the accepted answer. – Scott Dorman Apr 16 at 0:29
You can also detect the version and service pack installed, based on Mscorlib.dll file version.
http://msdn.microsoft.com/en-us/kb/kb00318785.aspx
answered Jun 12 '09 at 1:50
Priyatna Harun
11 1
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 Set
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
GetDotNetVersion(NDPKey.OpenSubKey(subkey).OpenSubKey("Full"), subkey
}
}
return versions;
}
private static void GetDotNetVersion(RegistryKey parentKey, string subVersionName
{
answered Mar 16 at 0:28
midspace
11 1
Using the Signum.Utilities library from SignumFramework (wich 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
4 of 5 6/9/2010 7:11 AMHow to detect what .NET Framework versions and service packs are insta... http://stackoverflow.com/questions/199080/how-to-detect-what-net-fram...
First time here? Check out the FAQ!
×
445 1 4
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
You're right, it'll be upgraded in the next release. – mapache Mar 17 '09 at 22:22
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." – DannySmurf May 21 '09 at 22:18
Well anyway the Signum.Utilities methods are still an interesting way.
edited Oct 16 '09 at 16:51 answered May 11 '09 at 18:34
Peter Mortensen Ugo Abano
2,773 1 4 18
for 64 bit OS the path would be HKEY_LOCAL_MACHINE\SOFTWARE\wow6432Node\Microsoft\NET
Framework Setup\NDP\
answered May 11 at 13:04
abhishek mehta
1
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 at 15:05
Not the answer you're looking for? Browse other questions tagged .net framework
installation version-detection or ask your own question.
question feed
5 of 5 6/9/2010 7:11 AM