Question

I'm having a problem with this:

Private Function Get_NT_Version()

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

    MsgBox(NT)

    Return NT

End Function

I'm running on Win7 so I want to obtain this value as decimal or double: "6.1" but what I get is this: "61"

This is what I want to do:

If Get_NT_Version() < 6.0 Then

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

end if

UPDATE:

Tried this idea too but returns a "61"

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

Solution 2

I found the solution using 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

Simple as that!

OTHER TIPS

This will work for you I just tested it in C# as well as converted my C# solution over to VB for you.

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

if you want to take it even a step further you can utilize the following code as well

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top