INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

Visual Basic (Microsoft) Versions 5/6 FAQ

Windows API

Get Operating System Version by LPlates
Posted: 17 Dec 03 (Edited 17 Dec 03)


Module...

Option Explicit

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

Public Const
VER_PLATFORM_WIN32s = 0        ' Win32s on Windows 3.1
Public Const VER_PLATFORM_WIN32_WINDOWS = 1 ' Windows 95, Windows 98, or Windows Me
Public Const VER_PLATFORM_WIN32_NT = 2      ' Windows NT, Windows 2000, Windows XP, or Windows Server 2003 family.

'                           Major     Minor
' OS              Platform  Version   Version  Build
' Windows 95      1         4          0
' Windows 98      1         4         10       1998
' Windows 98SE    1         4         10       2222
' Windows Me      1         4         90       3000
' NT 3.51         2         3         51
' NT              2         4          0       1381
' 2000            2         5          0
' XP              2         5          1       2600
' Server 2003     2         5          2

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 VER_PLATFORM_WIN32s           ' Win32s on Windows 3.1
              
getVersion = "Windows 3.1"
               
         Case VER_PLATFORM_WIN32_WINDOWS    ' Windows 95, Windows 98,
              
Select Case .dwMinorVersion   ' or Windows Me
                  
Case 0
                      getVersion = "Windows 95"
                  Case 10
                      If (OSInfo.dwBuildNumber And &HFFFF&) = 2222 Then
                          
getVersion = "Windows 98SE"
                      Else
                          
getVersion = "Windows 98"
                      End If
                  Case
90
                      getVersion = "Windows Me"
              End Select
     
         Case
VER_PLATFORM_WIN32_NT         ' Windows NT, Windows 2000, Windows XP,
              
Select Case .dwMajorVersion   ' or Windows Server 2003 family.
                  
Case 3
                      getVersion = "Windows NT 3.51"
                  Case 4
                      getVersion = "Windows NT 4.0"
                  Case 5
                      Select Case .dwMinorVersion
                          Case 0
                              getVersion = "Windows 2000"
                          Case 1
                              getVersion = "Windows XP"
                          Case 2
                              getVersion = "Windows Server 2003"
                      End Select
              End Select
                     
         Case Else
              
getVersion = "Failed"
               
     End Select
             
End With
End Function


Form...

Private Sub Command1_Click()
MsgBox getVersion
End Sub


Back to Visual Basic (Microsoft) Versions 5/6 FAQ Index
Back to Visual Basic (Microsoft) Versions 5/6 Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close