Dragon Drop
Dragon Drop - A Software Consultancy
Home      Our Products      Consultancy      Web Page Development      Services      Coding      Windows      External Resources     
Links      Newsletter      News And Issues      Books etc.      About Us     
CODING:   Exchange      Visual Basic      VBA      HomeSite     |     Coding Tools      Software Clinic     

Visual Basic Tips

Determining The Operating System

This code uses the GetVersionEX() API call to help determine the version of the operating system which is currently running.


Option Explicit





  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" _

      Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Boolean

      

  ' dwPlatforID Constants

  Public Const VER_PLATFORM_WIN32s = 0

  Public Const VER_PLATFORM_WIN32_WINDOWS = 1

  Public Const VER_PLATFORM_WIN32_NT = 2

'

  





Public Function IdentifyOperatingSystem() As String



  Dim rOsVersionInfo As OSVERSIONINFO

  Dim sOperatingSystem As String

  

  

  

  sOperatingSystem = "NONE"

  

  

  ' Pass the size of the structure into itself for the API call

  rOsVersionInfo.dwOSVersionInfoSize = Len(rOsVersionInfo)

  

  If GetVersionEx(rOsVersionInfo) Then

  

    Select Case rOsVersionInfo.dwPlatformId

    

      Case VER_PLATFORM_WIN32_NT

        

        If rOsVersionInfo.dwMajorVersion >= 5 Then

          If rOsVersionInfo.dwMinorVersion = 0 Then

            sOperatingSystem = "Windows 2000"

          Else

            sOperatingSystem = "Windows XP"

          End If

        Else

           sOperatingSystem = "Windows NT"

        End If

        

      Case VER_PLATFORM_WIN32_WINDOWS

        If rOsVersionInfo.dwMajorVersion >= 5 Then

           sOperatingSystem = "Windows ME"

        ElseIf rOsVersionInfo.dwMajorVersion = 4 And rOsVersionInfo.dwMinorVersion > 0 Then

           sOperatingSystem = "Windows 98"

        Else

           sOperatingSystem = "Windows 95"

        End If

        

      Case VER_PLATFORM_WIN32s

        sOperatingSystem = "Win32s"

        

    End Select

  End If



  IdentifyOperatingSystem = sOperatingSystem



End Function



Updates

If there are any suggestions for updates then please drop me a mail at malcolm.smith@dragondrop.com.