'/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
|