Attribute VB_Name = "WinVersion" ' VB module to retrieve the current Windows version ' Originally distributed with Aivosto Visustin flow chart generator ' www.aivosto.com Option Explicit Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 ' Maintenance string for PSS usage End Type Private Const VER_PLATFORM_WIN32_WINDOWS = 1 Private Const VER_PLATFORM_WIN32_NT = 2 Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long Public Enum EWinVersion wvError = 0 wvWin95 = 1 wvWin98 wvWinME wvWinNT351 wvWinNT4 wvWin2000 wvWinXP wvWinServer2003 wvNewer End Enum Public Function GetWinVersionEx() As EWinVersion ' Retrieve the current Windows version and return an enumerated constant value ' In the case of an error, return 0 Dim OSVI As OSVERSIONINFO ' Retrieve version information into OSVI OSVI.dwOSVersionInfoSize = Len(OSVI) If GetVersionEx(OSVI) <> 0 Then ' Version retrieved If OSVI.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then ' Win95/98/ME GetWinVersionEx = wvWin95 ' Default to Win95 If OSVI.dwMajorVersion = 4 Then Select Case OSVI.dwMinorVersion Case 0 ' 4.0 GetWinVersionEx = wvWin95 Case 10 ' 4.10 GetWinVersionEx = wvWin98 Case 90 ' 4.90 GetWinVersionEx = wvWinME End Select End If ElseIf OSVI.dwPlatformId = VER_PLATFORM_WIN32_NT Then ' WinNT/2000/XP/2003 Select Case OSVI.dwMajorVersion Case 3 ' NT 3.51 GetWinVersionEx = wvWinNT351 Case 4 ' NT 4.0 GetWinVersionEx = wvWinNT4 Case 5 Select Case OSVI.dwMinorVersion Case 0 GetWinVersionEx = wvWin2000 ' 5.0 Case 1 GetWinVersionEx = wvWinXP ' 5.1 Case 2 GetWinVersionEx = wvWinServer2003 ' 5.2 Case Else ' Unknown, newer Windows version GetWinVersionEx = wvNewer End Select Case Is > 5 ' Unknown, newer Windows version GetWinVersionEx = wvNewer End Select End If End If End Function