How to find/display Windows OS Version
Posted on January 4, 2009
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 | 'System & API - How to find/display Windows OS Version Option Explicit Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" _ (ByRef lpVersionInformation As OSVERSIONINFO) As Long Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 End Type Private Const VER_PLATFORM_WIN32s = 0 Private Const VER_PLATFORM_WIN32_WINDOWS = 1 Private Const VER_PLATFORM_WIN32_NT = 2 ' Return the Windows version. Public Function WindowsVersion() As String Dim info As OSVERSIONINFO Dim txt As String info.dwOSVersionInfoSize = Len(info) GetVersionEx info Select Case info.dwPlatformId Case VER_PLATFORM_WIN32s txt = "Windows " Case VER_PLATFORM_WIN32_WINDOWS If info.dwMajorVersion = 5 Then txt = "Windows 2000 " ElseIf info.dwMajorVersion < 4 Or (info.dwMajorVersion = 4 And info.dwMinorVersion = 0) Then txt = "Windows95 " Else txt = "Windows98 " End If Case VER_PLATFORM_WIN32_NT txt = "WindowsNT " End Select txt = txt & Format$(info.dwMajorVersion) & "." & Format$(info.dwMinorVersion) & _ vbCrLf & "Build " & Format$(info.dwBuildNumber) WindowsVersion = txt End Function 'How can I call this function: 'Debug.Print WindowsVersion() |