0

我有这个问题:

Private Function Get_NT_Version()

    Dim NT As Decimal = CDec(System.Environment.OSVersion.Version.ToString.Substring(0, 3))

    MsgBox(NT)

    Return NT

End Function

我在 Win7 上运行,所以我想获得这个值作为十进制或双精度:“ 6.1 ”但我得到的是:“ 61

这就是我想要做的:

If Get_NT_Version() < 6.0 Then

   msgbox("This application only works with an Aero compatible windows version")
   Application.Exit()

end if

更新:

也尝试过这个想法,但返回“61”

Dim s As Double = String.Format("{0}.{1}", System.Environment.OSVersion.Version.ToString.Split(".")(0), System.Environment.OSVersion.Version.ToString.Split(".")(1))
4

2 回答 2

2

这对你有用,我刚刚在 C# 中对其进行了测试,并为你将我的 C# 解决方案转换为 VB。

Private Function Get_NT_Version() As String
    Dim NT As String = Environment.OSVersion.Version.ToString()
    MessageBox.Show(NT.Substring(0, 3))
    Return NT
End Function

如果您想更进一步,您也可以使用以下代码

Private Sub Form1_Load(sender As Object, e As EventArgs)
    Dim str As String = Environment.OSVersion.Version.ToString()
    Dim OsName As String = ""
    If str.Contains("1.04") Then
        OsName = "Windows 1.0"
    ElseIf str.Contains("2.11") Then
        OsName = "Windows 2.0"
    ElseIf str.Contains("3") Then
        OsName = "Windows 3.0"
    ElseIf str.Contains("3.10.528") Then
        OsName = "Windows NT 3.1"
    ElseIf str.Contains("3.11 3.11") Then
        OsName = "Windows for Workgroups"
    ElseIf str.Contains("3.5 3.5.807") Then
        OsName = "Windows NT Workstation"
    ElseIf str.Contains("3.51 3.51.1057") Then
        OsName = "Windows NT Workstation"
    ElseIf str.Contains("4.0.950") Then
        OsName = "Windows 95"
    ElseIf str.Contains("4.0.1381") Then
        OsName = "Windows NT Workstation 4.0"
    ElseIf str.Contains("4.1.1998") Then
        OsName = "Windows 98"
    ElseIf str.Contains("4.1.2222") Then
        OsName = "Windows 98 Second Edition"
    ElseIf str.Contains("4.90.3000") Then
        OsName = "Windows Me"
    ElseIf str.Contains("5.0.2195") Then
        OsName = "Windows 2000 Professional"
    ElseIf str.Contains("5.1.2600") Then
        OsName = "Windows XP"
    ElseIf str.Contains("5.2.3790") Then
        OsName = "Windows XP Professional x64 Edition"
    ElseIf str.Contains("6.0.6000") Then
        OsName = "Windows Vista"
    ElseIf str.Contains("6.0.6002") Then
        OsName = "Windows Vista SP2"
    ElseIf str.Contains("6.1.7600") Then
        OsName = "Windows 7"
    ElseIf str.Contains("6.0.6000") Then
        OsName = "Windows Vista"
    ElseIf str.Contains("6.0.6000") Then
        OsName = "Windows Vista"
    End If
    MessageBox.Show(OsName + " " + Environment.OSVersion.ServicePack)
End Sub
于 2013-04-29T03:09:07.220 回答
1

我找到了使用 VAL 的解决方案:

#Region " Get NT Version "

    ' [ Get NT Version Function ]
    '
    ' // By Elektro H@cker
    '
    ' Examples :
    ' MsgBox(Get_NT_Version())
    ' If Get_NT_Version() < 6.0 Then MsgBox("This application only works with an Aero compatible windows version")

    Private Function Get_NT_Version() As Double

        Dim NT As Double = CDbl(Val(System.Environment.OSVersion.Version.ToString.Substring(0, 3)))

        ' INFO:
        ' -----
        ' 3.1 = Windows NT 3.1
        ' 3.5 = Windows NT 3.5
        ' 4.0 = Windows NT 4.0
        ' 5.0 = Windows 2000
        ' 5.1 = Windows XP / Windows Fundamentals for Legacy PCs
        ' 5.2 = Windows XP 64 Bit / Windows server 2003 / Windows server 2003 R2 / Windows home Server /
        ' 6.0 = Windows VISTA / Windows server 2008
        ' 6.1 = Windows 7 / Windows server 2008 R2
        ' 6.2 = Windows 8 / Windows 8 Phone / Windows Server 2012

        Return NT

    End Function

#End Region

就那么简单!

于 2013-04-29T03:16:20.517 回答