Search code examples
.netwindowsvb.netwindowsversion

Convert Windows version number to double


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))

Solution

  • 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!