Hi,
I want to detect the version using GetVersionExA.
With the following module I can do this, but there is a problem in detecting Windows Vista against Windows Server 2008 because they have the same minor and major versions.
According to Microsoft I have to use use OSVERSIONINFOEX Structure. It contains operating system version information. The information includes major and minor version numbers, a build number, a platform identifier, and information about product suites and the latest Service Pack installed on the system. This structure is used with the GetVersionEx and VerifyVersionInfo functions.
The version numbers for Windows Server 2008 and Windows Vista are identical, both version numbers are 6, you must also test whether the wProductType member of OSVERSIONINFOEX Structure is VER_NT_WORKSTATION. If wProductType is VER_NT_WORKSTATION, the operating system is Windows Vista; otherwise, it is Windows Server 2008.
The problem is that .wProductType always returns 0 rather than VER_NT_WORKSTATION...
Here is my module, which I dont know where its wrong:
I want to detect the version using GetVersionExA.
With the following module I can do this, but there is a problem in detecting Windows Vista against Windows Server 2008 because they have the same minor and major versions.
According to Microsoft I have to use use OSVERSIONINFOEX Structure. It contains operating system version information. The information includes major and minor version numbers, a build number, a platform identifier, and information about product suites and the latest Service Pack installed on the system. This structure is used with the GetVersionEx and VerifyVersionInfo functions.
The version numbers for Windows Server 2008 and Windows Vista are identical, both version numbers are 6, you must also test whether the wProductType member of OSVERSIONINFOEX Structure is VER_NT_WORKSTATION. If wProductType is VER_NT_WORKSTATION, the operating system is Windows Vista; otherwise, it is Windows Server 2008.
The problem is that .wProductType always returns 0 rather than VER_NT_WORKSTATION...
Here is my module, which I dont know where its wrong:
Code:
Public Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFOEX) As Integer
Public Type OSVERSIONINFOEX
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
wServicePackMajor As Integer
wServicePackMinor As Integer
wSuiteMask As Integer
wProductType As Byte
wReserved As Byte
End Type
Public Function GetVersion() As String
On Error Resume Next
Dim osinfo As OSVERSIONINFOEX
Dim retvalue As Integer
osinfo.dwOSVersionInfoSize = 148
osinfo.szCSDVersion = Space$(128)
retvalue = GetVersionExA(osinfo)
With osinfo
MsgBox .wProductType
Select Case .dwPlatformId
Case 1
Select Case .dwMinorVersion
Case 0
GetVersion = "Windows 95"
Case 10
GetVersion = "Windows 98"
Case 90
GetVersion = "Windows Millennium"
End Select
Case 2
Select Case .dwMajorVersion
Case 3
GetVersion = "Windows NT 3.51"
Case 4
GetVersion = "Windows NT 4.0"
Case 5
Select Case .dwMinorVersion
Case 0
GetVersion = "Windows 2000"
Case 1
GetVersion = "Windows XP"
Case 2
GetVersion = "Windows Server 2003"
End Select
Case 6
If .wProductType = "VER_NT_WORKSTATION" Then
GetVersion = "Windows Vista"
Else
GetVersion = "Windows Server 2008"
End If
End Select
Case Else
GetVersion = "Unknown Windows"
End Select
End With
End Function