在VB.NET中获取.NET Framework版本的方法如下:
Imports System.Runtime.InteropServices
Module Module1
Sub Main()
Dim version As String = GetDotNetVersion()
Console.WriteLine("The .NET Framework version is: " & version)
End Sub
Private Function GetDotNetVersion() As String
Dim regKey As Object = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full")
If regKey IsNot Nothing Then
Dim releaseKey As Integer = CInt(regKey.GetValue("Release"))
If releaseKey >= 528040 Then
Return "4.8 or later"
ElseIf releaseKey >= 461808 Then
Return "4.7.2 or later"
ElseIf releaseKey >= 461308 Then
Return "4.7.1 or later"
ElseIf releaseKey >= 460798 Then
Return "4.7 or later"
ElseIf releaseKey >= 394802 Then
Return "4.6.2 or later"
ElseIf releaseKey >= 394254 Then
Return "4.6.1 or later"
ElseIf releaseKey >= 393295 Then
Return "4.6 or later"
ElseIf releaseKey >= 379893 Then
Return "4.5.2 or later"
ElseIf releaseKey >= 378675 Then
Return "4.5.1 or later"
ElseIf releaseKey >= 378389 Then
Return "4.5 or later"
End If
End If
Return "Not Installed"
End Function
End Module
这段代码将会返回.NET Framework的版本号,并在控制台中输出结果。需要注意的是,这段代码只能在Windows操作系统上运行。
领取专属 10元无门槛券
手把手带您无忧上云