这里也提出了类似的问题,但这是针对。net 3.5的。具体来说,我正在寻找以下:

确定安装了哪些.NET Framework版本和服务包的正确方法是什么? 是否有可以使用的注册表项列表? 框架版本之间是否存在依赖关系?


当前回答

注册表是检测是否安装了特定版本的框架的官方方法。

需要更改哪些注册表项取决于您正在寻找的框架版本:

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

一般来说,你在寻找:

"Install"=dword:00000001

除了。net 1.0,它的值是一个字符串(REG_SZ)而不是一个数字(REG_DWORD)。

确定服务包级别遵循类似的模式:

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

如你所见,如果你在Windows Media Center或Windows XP Tablet Edition上运行,. net 1.0的SP级别会发生变化。同样,. net 1.0使用字符串值,而其他所有的都使用DWORD。

对于。net 1.0,这些键的字符串值的格式为#,#,####,#。最后一个#是Service Pack级别。

虽然我没有明确要求,如果你想知道框架的确切版本号,你可以使用这些注册表项:

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)

同样,. net 1.0使用字符串值,而其他所有的都使用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.

针对.NET 4.5的更新

如果安装了。net 4.5,那么注册表中将没有v4.5键。相反,你必须检查HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Full键是否包含一个名为Release的值。如果存在这个值,则表示安装了。net 4.5,否则没有。更多细节可以在这里和这里找到。

其他回答

有一个可用的GUI工具,ASoft . net Version Detector,它一直被证明是高度可靠的。它可以通过在命令行上指定XML输出的文件名来创建XML文件。

您可以将其用于自动化。这是一个很小的程序,用非编程语言编写的。NET依赖语言,不需要安装。

微软在下面的知识库文章中给出了这个问题的官方答案:

文章ID: 318785 -最近审查:2008年11月7日-修订:20.1 如何确定安装了哪些版本的.NET Framework以及是否应用了服务包

不幸的是,它似乎不能工作,因为在2.0目录中的mscorlib.dll版本有一个2.0版本,并且在3.0或3.5目录中没有mscorlib.dll版本,即使安装了3.5 SP1…为什么微软的官方回答会如此错误?

对于64位操作系统,路径为:

HKEY_LOCAL_MACHINE\SOFTWARE\wow6432Node\Microsoft\NET Framework Setup\NDP\

我需要找出我电脑上的。net框架的版本,我所做的就是打开控制面板,选择“卸载程序”选项。之后,我把程序按名称分类,找到了Microsoft . net Framework 4客户端配置文件。

注册表是检测是否安装了特定版本的框架的官方方法。

需要更改哪些注册表项取决于您正在寻找的框架版本:

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

一般来说,你在寻找:

"Install"=dword:00000001

除了。net 1.0,它的值是一个字符串(REG_SZ)而不是一个数字(REG_DWORD)。

确定服务包级别遵循类似的模式:

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

如你所见,如果你在Windows Media Center或Windows XP Tablet Edition上运行,. net 1.0的SP级别会发生变化。同样,. net 1.0使用字符串值,而其他所有的都使用DWORD。

对于。net 1.0,这些键的字符串值的格式为#,#,####,#。最后一个#是Service Pack级别。

虽然我没有明确要求,如果你想知道框架的确切版本号,你可以使用这些注册表项:

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)

同样,. net 1.0使用字符串值,而其他所有的都使用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.

针对.NET 4.5的更新

如果安装了。net 4.5,那么注册表中将没有v4.5键。相反,你必须检查HKLM\Software\Microsoft\NET Framework Setup\NDP\v4\Full键是否包含一个名为Release的值。如果存在这个值,则表示安装了。net 4.5,否则没有。更多细节可以在这里和这里找到。