Highlights
All Snippets
Top 100 Snippets
Librarians
gbCodeLib

By Language
VB6
JavaScript
Perl
HTML
SQL
Java
DOS

GBIC >> Source Code >> Visual Basic >> Snippet

Get Windows version



Public Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer

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


MsgBox GetVersion()

Public Function getVersion() As String
   Dim osinfo As OSVERSIONINFO
   Dim retvalue As Integer

  osinfo.dwOSVersionInfoSize = 148
  osinfo.szCSDVersion = Space$(128)
  retvalue = GetVersionExA(osinfo)

   With osinfo
   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
                If .dwMinorVersion = 0 Then
                   getVersion = "Windows 2000"
                Else
                   getVersion = "Windows XP"
                End If
       End Select

    Case Else
      getVersion = "Failed"
End Select

   End With
End Function


'----------------------------------------
'also info is in the registry at
HKLM \ Software \ Microsoft \ Windows \ CurrentVersion
Version
VersionNumber
SubVersionNumber