Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleGet the Windows operating system version
KeywordsWindows version, version, operating system
CategoriesWindows, API
 
Use the GetVersionEx API function.
 
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 Const VER_PLATFORM_WIN32s = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2

' Return the Windows version.
Public Function WindowsVersion() As String
Dim info As OSVERSIONINFO
Dim txt As String

    info.dwOSVersionInfoSize = Len(info)
    GetVersionEx info

    Select Case info.dwPlatformId
        Case VER_PLATFORM_WIN32s
            txt = "Windows "
        Case VER_PLATFORM_WIN32_WINDOWS
            If info.dwMajorVersion = 5 Then
                txt = "Windows 2000 "
            ElseIf info.dwMajorVersion < 4 Or _
              (info.dwMajorVersion = 4 And _
               info.dwMinorVersion = 0) _
            Then
                txt = "Windows95 "
            Else
                txt = "Windows98 "
            End If
        Case VER_PLATFORM_WIN32_NT
            txt = "WindowsNT "
    End Select

    txt = txt & Format$(info.dwMajorVersion) & _
        "." & Format$(info.dwMinorVersion) & _
        vbCrLf & "Build " & Format$(info.dwBuildNumber)
    WindowsVersion = txt
End Function
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated