Private Function DisplayOS() As String
Dim osvi As OSVERSIONINFO, xosvi As OSVERSIONINFOEX
Dim SStatus As Boolean 'boolean takes less resources than Variant
Dim xInfo As Boolean 'check if OS has extra info (ie: Home Edition)
'Variables to hold operating system information
Dim platformID As String, BuildNumber As String, MinorVer As String, _
MajorVer As String, WindowsVer As String, WindowsDistro As String, _
WindowsType As String, ServicePack As String
osvi.dwOSVersionInfoSize = 148 'Len(osvi)
xInfo = False
SStatus = GetVersionEx(osvi) 'GetVersionEx API
If SStatus = True Then 'If GetVersionEx doesn't return false
platformID = osvi.dwPlatformID
majorversion = osvi.dwMajorVersion
minorversion = osvi.dwMinorVersion
BuildNumber = osvi.dwBuildNumber
ServicePack = osvi.szCSDVersion
WindowsVer = platformID & "." & majorversion & "." & minorversion
Select Case WindowsVer
Case Is < WIN95
WindowsDistro = "Windows 3.x"
Case WIN95
If (InStr(1, UCase(osvi.szCSDVersion), "B")) Or (InStr(1, UCase(osvi.szCSDVersion), "C")) Then
WindowsDistro = "Windows 95 OSR2"
Else
WindowsDistro = "Windows 95"
End If
Case WIN98
If (InStr(1, UCase(osvi.szCSDVersion), "A")) Then
WindowsDistro = "Windows 98 SE"
Else
WindowsDistro = "Windows 98"
End If
Case WINME
WindowsDistro = "Windows ME"
Case WINNT
WindowsDistro = "Windows NT 3.51"
Case WINNT4
WindowsDistro = "Windows NT 4.00"
If UCase(Trim(osvi.szCSDVersion)) >= "SERVICE PACK 6" Then
xInfo = True 'Gather More
GoTo xInfo 'Information
End If
Case WIN2K
WindowsDistro = "Windows 2000"
xInfo = True
GoTo xInfo
Case WINXP
WindowsDistro = "Windows XP"
xInfo = True
GoTo xInfo
Case WINNTS
WindowsDistro = "Windows Server 2003"
xInfo = True
GoTo xInfo
Case Else
WindowsDistro = "Unknown Windows Version"
End Select
End If
xInfo:
If xInfo = True Then
xosvi.dwOSVersionInfoSize = 156 'Len(xosvi)
SStatus = GetVersionAdv(xosvi)
If SStatus = True Then
Select Case xosvi.dwMajorVersion
Case &H4 'NT 4
Select Case xosvi.wProductType
Case WinProdType.VER_NT_DOMAIN_CONTROLLER
WindowsType = "Domain Controller"
Case WinProdType.VER_NT_SERVER
If (xosvi.wSuiteMask And WinSuiteMask.VER_SUITE_ENTERPRISE > 0) Then
WindowsType = "Advanced Server"
Else
WindowsType = "Server"
End If
Case WinProdType.VER_NT_WORKSTATION
WindowsType = "Workstation"
End Select
Case &H5 'WIN2K/XP/.NET
Select Case xosvi.dwMinorVersion
Case &H0 'WIN2K
Select Case xosvi.wProductType
Case WinProdType.VER_NT_DOMAIN_CONTROLLER
WindowsType = "Domain Controller"
Case WinProdType.VER_NT_SERVER
If (xosvi.wSuiteMask And WinSuiteMask.VER_SUITE_ENTERPRISE > 0) Then
WindowsType = "Advanced Server"
Else
WindowsType = "Server"
End If
Case WinProdType.VER_NT_WORKSTATION
WindowsType = "Professional"
End Select
Case &H1 'XP
Select Case xosvi.wProductType
Case WinProdType.VER_NT_DOMAIN_CONTROLLER
WindowsType = "Domain Controller"
Case WinProdType.VER_NT_SERVER
WindowsType = "Server"
Case WinProdType.VER_NT_WORKSTATION
If (xosvi.wSuiteMask And WinSuiteMask.VER_SUITE_PERSONAL > 0) Then
WindowsType = "Home Edition"
Else
WindowsType = "Professional"
End If
End Select
Case &H2 '.NET
Select Case xosvi.wProductType
Case WinProdType.VER_NT_DOMAIN_CONTROLLER
WindowsType = "Domain Controller"
Case WinProdType.VER_NT_SERVER
If xosvi.wSuiteMask Then
If WinSuiteMask.VER_SUITE_BLADE Then
WindowsType = "Web Server"
ElseIf WinSuiteMask.VER_SUITE_DATACENTER Then
WindowsType = "Datacenter Server"
ElseIf WinSuiteMask.VER_SUITE_ENTERPRISE Then
WindowsType = "Enterprise Server"
Else
WindowsType = "Server" 'Personal?
End If
End If
Case WinProdType.VER_NT_WORKSTATION
WindowsType = vbNullString
End Select
Case Else
WindowsType = vbNullString
End Select
Case Else
WindowsType = vbNullString
End Select
End If
End If
DisplayOS = WindowsDistro & Space(1) & WindowsType & Space(1) & ServicePack
End Function