Attribute VB_Name = "ModOSVersion"
' ModOSVersion.bas

Option Explicit

Public OSVersion As Integer

Private Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type

Private Declare Function GetVersionEx Lib "kernel32.dll" Alias "GetVersionExA" _
    (OSInfo As OSVERSIONINFO) As Long
    
Public Win$


Public Function winOSver() As Integer
Dim typOS As OSVERSIONINFO
   On Error GoTo errHandler
   OSVersion = 0
     ' MSDN: Before calling the GetVersionEx function, set the dwOSVersionInfoSize
     ' member of the OSVERSIONINFO data structure to sizeof(OSVERSIONINFO).
   typOS.dwOSVersionInfoSize = Len(typOS)
   If GetVersionEx(typOS) = 0 Then                 ' Zero is failure
      Exit Function
   End If
   With typOS
      If .dwPlatformId = 1 And .dwMajorVersion = 4 And .dwMinorVersion = 0 Then
           OSVersion = 3: Win$ = "Win95"
      ElseIf .dwPlatformId = 1 And .dwMajorVersion = 4 And .dwMinorVersion = 10 Then
           OSVersion = 4: Win$ = "Win98"
      ElseIf .dwPlatformId = 1 And .dwMajorVersion = 4 And .dwMinorVersion = 90 Then
           OSVersion = 5: Win$ = "WinME"
      ElseIf .dwPlatformId = 2 And .dwMajorVersion = 3 And .dwMinorVersion = 51 Then
           OSVersion = 1: Win$ = "WinNT 3.51"
      ElseIf .dwPlatformId = 2 And .dwMajorVersion = 4 And .dwMinorVersion = 0 Then
           OSVersion = 2: Win$ = "WinNT 4.0"
           
      ElseIf .dwPlatformId = 2 And .dwMajorVersion = 5 And .dwMinorVersion = 0 Then
           OSVersion = 6: Win$ = "Win2000 NT"
      ElseIf .dwPlatformId = 2 And .dwMajorVersion = 5 And .dwMinorVersion = 1 Then
           OSVersion = 7: Win$ = "WinXP"
      ElseIf .dwPlatformId = 2 And .dwMajorVersion >= 6 Then
           OSVersion = 8: Win$ = "Win Vista"
      
      Else
           OSVersion = 0: Win$ = "Win Unknown"
      End If
   End With
   Exit Function
errHandler:
End Function

