Question : Detecting version numbers

I need an up to date way to detect the Operating system version - all the way up to Windows 7.  Any ideas?

Answer : Detecting version numbers

Copy/paste the attached into a new Module (name it something like "basGetOSInfo"). To use it, call it like this:

Msgbox OSVersion

This will return the current version, and does handle Windows 7. I've tested it on WinXP, Vista, and Windows7
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
99:
100:
101:
'/in the General Declarations section
Option Explicit

Private Type OSVERSIONINFOEX
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformID As Long
szCSDVersion As String * 128
dwServicePackMajor As Integer
dwServicePackMinor As Integer
wSuiteMask As Integer
wProductType As Byte
wReserved As Byte
End Type


Private Const VER_PLATFORM_WIN32s = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2

Private Const VER_NT_WORKSTATION = &H1
Private Const VER_NT_SERVER = &H3
Private Const VER_NT_DOMAIN_CONTROLLER = &H2

Private Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFOEX) As Integer


Public Function OSVersion() As String
    
    Dim udtOSVersion As OSVERSIONINFOEX
    Dim lMajorVersion  As Long
    Dim lMinorVersion As Long
    Dim lPlatformID As Long
    Dim lProductType As Long
    Dim sAns As String
    
    
    udtOSVersion.dwOSVersionInfoSize = Len(udtOSVersion)
    GetVersionExA udtOSVersion
    lMajorVersion = udtOSVersion.dwMajorVersion
    lMinorVersion = udtOSVersion.dwMinorVersion
    lPlatformID = udtOSVersion.dwPlatformID
    lProductType = udtOSVersion.wProductType
    
    Select Case lMajorVersion
        Case 6
          If lMinorVersion = 0 Then
            If lProductType = VER_NT_WORKSTATION Then
              sAns = "Windows Vista"
            Else
              sAns = "Windows Server 2008"
            End If
            
          ElseIf lMinorVersion = 1 Then
            If lProductType = VER_NT_WORKSTATION Then
              sAns = "Windows 7"
            Else
              sAns = "Windows Server 2008 R2"
            End If
          End If
        Case 5
        
            ' Added the following to give suppport for Windows XP!
            If lMinorVersion = 0 Then
            
                sAns = "Windows 2000"
                
            ElseIf lMinorVersion = 1 Then
            
                sAns = "Windows XP"
            
            End If
            
                
                
        Case 4
            If lPlatformID = VER_PLATFORM_WIN32_NT Then
                sAns = "Windows NT 4.0"
            Else
                sAns = IIf(lMinorVersion = 0, _
                "Windows 95", "Windows 98")
            End If
        Case 3
            If lPlatformID = VER_PLATFORM_WIN32_NT Then
                sAns = "Windows NT 3.x"
 
              'below should only happen if person has Win32s
                'installed
            Else
                sAns = "Windows 3.x"
            End If
            
        Case Else
            sAns = "Unknown Windows Version"
    End Select
                    
    OSVersion = sAns
    
End Function
Random Solutions  
 
programming4us programming4us