VB icon

Get Windows Version

Email
Submitted on: 1/25/2015 8:02:00 PM
By: Mike Whitman (from psc cd)  
Level: Intermediate
User Rating: By 3 Users
Compatibility: VB 6.0
Views: 516
 
     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)
 

Windows API/Global Declarations:

Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
'**************************************
'Windows API/Global Declarations for :Get Windows Version
'**************************************
Public Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: Get Windows Version
' Description: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)
' By: Mike Whitman (from psc cd)
'
' Inputs:Eg.
lblOS.Caption = GetWindowsVersion
'
' Returns:O.S's specified
'
' Side Effects:N/A
'**************************************

'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


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.