VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Get Windows Version

by Mike Whitman (1 Submission)
Category: Windows System Services
Compatability: Visual Basic 5.0
Difficulty: Intermediate
Date Added: Wed 3rd February 2021
Rating: (3 Votes)

Finds the OS version of Windows 95/SP1/OSR2, Win 98/SP1/SE, Win ME, Win NT 3.51/4.0, Windows 2000, Windows XP, Windows CE 1.0/2.0/2.1/3.0. (Revised Version)

Inputs
Eg. lblOS.Caption = GetWindowsVersion
Code Returns
O.S's specified
Side Effects
N/A
API Declarations
Public Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer

Rate Get Windows Version

'IN MODULE
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 Function GetWindowsVersion() As String
 Dim OSInfo As OSVERSIONINFO
 Dim Ret As Integer
  
 OSInfo.dwOSVersionInfoSize = 148
 OSInfo.szCSDVersion = Space$(128)
 Ret = GetVersionExA(OSInfo)
With OSInfo
 Select Case .dwPlatformId
  Case 1
   If .dwMinorVersion < 10 Then
    If .dwBuildNumber = 950 Then
     GetWindowsVersion = "Windows 95"
    ElseIf .dwBuildNumber > 950 Or .dwBuildNumber <= 1080 Then
     GetWindowsVersion = "Windows 95 SP1"
    Else
     GetWindowsVersion = "Windows 95 OSR2"
    End If
   ElseIf .dwMinorVersion = 10 Then
    If .dwBuildNumber = 1998 Then
     GetWindowsVersion = "Windows 98"
    ElseIf .dwBuildNumber > 1998 Or .dwBuildNumber < 2183 Then
     GetWindowsVersion = "Windows 98 SP1"
    ElseIf .dwBuildNumber >= 2183 Then
     GetWindowsVersion = "Windows 98 SE"
    End If
   Else
    GetWindowsVersion = "Windows ME"
   End If
  Case 2
   If .dwMajorVersion = 3 Then
    GetWindowsVersion = "Windows NT 3.51"
   ElseIf .dwMajorVersion = 4 Then
    GetWindowsVersion = "Windows NT 4.0"
   ElseIf .dwMajorVersion = 5 Then
    If .dwMinorVersion = 0 Then
     GetWindowsVersion = "Windows 2000"
    Else
     GetWindowsVersion = "Windows XP"
    End If
   End If
  Case 3
   If .dwMajorVersion = 1 Then
    GetWindowsVersion = "Windows CE 1.0"
   ElseIf .dwMajorVersion = 2 Then
    If .dwMinorVersion = 0 Then
     GetWindowsVersion = "Windows CE 2.0"
    Else
     GetWindowsVersion = "Windows CE 2.1"
    End If
   Else
    GetWindowsVersion = "Windows CE 3.0"
   End If
  Case Else
   GetWindowsVersion = "Unable to get Windows Version"
 End Select
End With
End Function

Download this snippet    Add to My Saved Code

Get Windows Version Comments

No comments have been posted about Get Windows Version. Why not be the first to post a comment about Get Windows Version.

Post your comment

Subject:
Message:
0/1000 characters