Public Function GetWindowsVersion() As String
' Purpose: Find Windows version
On Error GoTo ErrHandler
Dim strOSName As String
Dim OSInfo As OSVERSIONINFO
OSInfo.dwOSVersionInfoSize = 148
OSInfo.szCSDVersion = Space$(128)
' API call to get operating system info.
Call GetVersionEx(OSInfo)
With OSInfo
Select Case .dwPlatformId
Case 1
Select Case .dwMinorVersion
Case 0
strOSName = "Windows 95"
Case 10
strOSName = "Windows 98"
Case 90
strOSName = "Windows Millennium"
End Select
Case 2
Select Case .dwMajorVersion
Case 3
strOSName = "Windows NT 3.51"
Case 4
strOSName = "Windows NT 4.0"
Case 5
If .dwMinorVersion = 0 Then
strOSName = "Windows 2000"
Else
strOSName = "Windows XP"
End If
End Select
Case Else
strOSName = "Failed"
End Select
End With
GetWindowsVersion = strOSName
ExitHere:
Exit Function
ErrHandler:
Debug.Print Err, Err.Description
Resume ExitHere
End Function