您能分享一个VB脚本,用于检查计算机上是否安装了.NET 2.0吗?
我在网上搜索了一下,大多数“检查是否安装了.NET”的应用程序只是查找特定的注册表键,忽略了安装可能已损坏的事实。
基本上,我正在寻找一个脚本,它尝试创建一个.NET对象(应该可以创建-例如System.Object),如果失败了-.NET要么未安装,要么安装已损坏(因此与根本没有安装.NET一样)。
您能分享一个VB脚本,用于检查计算机上是否安装了.NET 2.0吗?
我在网上搜索了一下,大多数“检查是否安装了.NET”的应用程序只是查找特定的注册表键,忽略了安装可能已损坏的事实。
基本上,我正在寻找一个脚本,它尝试创建一个.NET对象(应该可以创建-例如System.Object),如果失败了-.NET要么未安装,要么安装已损坏(因此与根本没有安装.NET一样)。
Option Explicit
Dim oShell
Dim value
''#If the key isn't there when we try to read it, an error will be generated
''# that we will later test for, so we want to automatically resume execution.
On Error Resume Next
''#Try reading the registry value
Set oShell = CreateObject("WScript.Shell")
value = oShell.RegRead("HKLM\SOFTWARE\Microsoft\.NETFramework\Policy\v2.0\50727")
''#Catch the error
If Err.Number = 0 Then
''#Error code 0 indicates success
MsgBox("Version 2.0 of the .NET Framework is installed.")
Else
''#Any other error code indicates failure
MsgBox("Version 2.0 of the .NET Framework is NOT installed.")
End If
On Error Resume Next
。请保留HTML标记。On Error Goto 0 ''#Turn "On Error Resume Next" back off!
编辑:如果您确定要通过实例化一个常见框架对象来确定.NET安装的有效性,则该脚本与之前非常相似。 (实际上,它甚至比访问注册表更简单。)与之前一样,使用CreateObject
,但这次是用于实例化基类System.Object
的对象:
On Error Resume Next
Dim testObj
Set testObj = CreateObject("System.Object")
If Err.Number = 0 Then
MsgBox("Success")
Else
MsgBox("Failure")
End If
''official MSDN verison 2.0
value = oShell.RegRead("HKEY_LOCAL_MACHINE\Software\Microsoft\NET Framework Setup\NDP\v2.0.50727\Version")
''#Catch the error
If Err.Number = 0 Then
''#Error code 0 indicates success
MsgBox("Version 2.0 of the official .NET Framework is installed.")
Else
''#Any other error code indicates failure
MsgBox("Version 2.0 of the official .NET Framework is NOT installed.")
End If
要确定.NET FRAMEWORK 2是否正确安装,我建议编写一个脚本来查找“两个事项”:
检查RegKey是否仍然存在,就像'Cody Gray'所示。
我会编写一段代码来检查位于Windows目录中的NET FRAMEWORK 2是否小于例如75 MB(通常约为82-87 MB),如果是,则未安装或已损坏。
将这两个代码组合在一起,您将能够知道NET FRAMEWORK 2是否已正确安装在用户的计算机上。