如何检测安装了哪些.NET Framework版本和Service Pack?

本文翻译自:How do I detect what .NET Framework versions and service packs are installed?

A similar question was asked here , but it was specific to .NET 3.5. 在这里提出类似的问题,但它特定于.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? 确定安装哪些.NET Framework版本和Service Pack的正确方法是什么?
  2. Is there a list of registry keys that can be used? 是否有可以使用的注册表项列表?
  3. Are there any dependencies between Framework versions? Framework版本之间是否存在任何依赖关系?

#1楼

参考:https://stackoom.com/question/PMY/如何检测安装了哪些-NET-Framework版本和Service-Pack


#2楼

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. 我只需要找出计算机上使用的.NET Framework版本,然后要做的就是转到控制面板,然后选择“卸载程序”选项。 After that, I sorted the programs by name, and found Microsoft .NET Framework 4 Client Profile. 之后,我按名称对程序进行了排序,并找到了Microsoft .NET Framework 4 Client Profile。


#3楼

See How to: Determine Which .NET Framework Versions Are Installed (MSDN). 请参阅如何:确定安装了.NET Framework版本 (MSDN)。

MSDN proposes one function example that seems to do the job for version 1-4. MSDN提出了一个似乎可以完成版本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. 请注意,对于“版本4.5及更高版本”,还有另一个功能。


#4楼

Enumerate the subkeys of HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP . 枚举HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\NET Framework Setup\\NDP Each subkey is a .NET version. 每个子项都是.NET版本。 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. 如果计算机上存在,则应该具有Install=1值;如果显示了Service Pack,则应该具有SP值;如果使用MSI安装,则应该具有MSI=1值。 (.NET 2.0 on Windows Vista doesn't have the last one for example, as it is part of the OS.) (例如,Windows Vista上的.NET 2.0没有最后一个,因为它是操作系统的一部分。)


#5楼

The registry is the official way to detect if a specific version of the Framework is installed. 注册表是检测是否安装了特定版本的Framework 的官方方法

在此处输入图片说明

Which registry keys are needed change depending on the Framework version you are looking for: 根据您要查找的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

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 ). .NET 1.0除外,该值是字符串( REG_SZ )而不是数字( REG_DWORD )。

Determining the service pack level follows a similar pattern: 确定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\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. 如您所见,如果您在Windows Media Center或Windows XP Tablet Edition上运行,则确定.NET 1.0的SP级别会更改。 Again, .NET 1.0 uses a string value while all of the others use a DWORD. 同样,.NET 1.0使用字符串值,而其他所有使用DWORD。

For .NET 1.0 the string value at either of these keys has a format of #,#,####,#. 对于.NET 1.0,这两个键中的任何一个的字符串值的格式都为#,#,####,#。 The last # is the Service Pack level. 最后一个#是Service Pack级别。

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的确切版本号,可以使用以下注册表项:

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

Additional Notes 附加条款

  • for .NET 1.0 the string value at either of these keys has a format of #,#,####,# . 对于.NET 1.0,这两个键之一的字符串值的格式为#,#,####,# The #,#,#### portion of the string is the Framework version. 字符串的#,#,####部分是Framework版本。

  • for .NET 1.1, we use the name of the registry key itself, which represents the version number. 对于.NET 1.1,我们使用注册表项本身的名称,它表示版本号。

  • 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. 最后,如果您查看依赖关系,.NET 3.0将为.NET 2.0添加其他功能,因此.NET 2.0和.NET 3.0在安装时都必须撤消,以正确地说已安装.NET 3.0。 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 3.5向.NET 2.0和.NET 3.0添加了附加功能,因此.NET 2.0,.NET 3.0和.NET 3都应评估为已安装,以正确地说已安装.NET 3.5。

  • .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.0安装了新版本的CLR(CLR版本4.0),该版本可以与CLR 2.0并行运行。

Update for .NET 4.5 .NET 4.5更新

There won't be a v4.5 key in the registry if .NET 4.5 is installed. 如果安装了.NET 4.5,则注册表中将没有v4.5密钥。 Instead you have to check if the HKLM\\Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full key contains a value called Release . 相反,您必须检查HKLM\\Software\\Microsoft\\NET Framework Setup\\NDP\\v4\\Full键是否包含一个称为Release的值。 If this value is present, .NET 4.5 is installed, otherwise it is not. 如果存在此值,则安装.NET 4.5,否则不安装。 More details can be found here and here . 可以在此处此处找到更多详细信息。


#6楼

Update for .NET 4.5.1 .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. 现在,.NET 4.5.1可用了,需要检查注册表中名为Release的键的实际值,而不仅仅是它的存在。 A value of 378758 means that .NET Framework 4.5.1 is installed. 值378758表示已安装.NET Framework 4.5.1。 However, as described here this value is 378675 on Windows 8.1. 但是,如此处所述此值在Windows 8.1上为378675。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值