Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Get Operating System Version

Windows API

Get Operating System Version

by  LPlates  Posted    (Edited  )

Module...

[blue]Option Explicit

Public Declare Function [/blue]GetVersionExA [blue]Lib [/blue]"kernel32" _
(lpVersionInformation [blue]As [/blue]OSVERSIONINFO) As [blue]Integer

Public Type [/blue]OSVERSIONINFO
dwOSVersionInfoSize [blue]As Long
[/blue]dwMajorVersion [blue]As Long
[/blue]dwMinorVersion [blue]As Long
[/blue]dwBuildNumber [blue]As Long
[/blue]dwPlatformId [blue]As Long
[/blue]szCSDVersion [blue]As String [/blue]* 128
[blue]End Type

Public Const [/blue]VER_PLATFORM_WIN32s = 0 [green]' Win32s on Windows 3.1
[/green][blue]Public Const [/blue]VER_PLATFORM_WIN32_WINDOWS = 1 [green]' Windows 95, Windows 98, or Windows Me
[/green][blue]Public Const [/blue]VER_PLATFORM_WIN32_NT = 2 [green]' Windows NT, Windows 2000, Windows XP, or Windows Server 2003 family.
Code:
'                           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
[/green][blue]Public Function [/blue]getVersion() [blue]As String
Dim [/blue]OSInfo [blue]As [/blue]OSVERSIONINFO
[blue]Dim [/blue]retvalue [blue]As Integer

[/blue]OSInfo.dwOSVersionInfoSize = 148
OSInfo.szCSDVersion = Space$(128)
retvalue = GetVersionExA(OSInfo)

[blue]With [/blue]OSInfo
[blue]Select Case [/blue].dwPlatformId
[blue]Case [/blue]VER_PLATFORM_WIN32s [green]' Win32s on Windows 3.1
[/green]getVersion = "Windows 3.1"

[blue]Case [/blue]VER_PLATFORM_WIN32_WINDOWS [green]' Windows 95, Windows 98,
[/green][blue]Select Case [/blue].dwMinorVersion [green]' or Windows Me
[/green][blue]Case [/blue]0
getVersion = "Windows 95"
[blue]Case [/blue]10
[blue]If [/blue](OSInfo.dwBuildNumber [blue]And [/blue]&HFFFF&) = 2222 [blue]Then
[/blue]getVersion = "Windows 98SE"
[blue]Else
[/blue]getVersion = "Windows 98"
[blue]End If
Case [/blue]90
getVersion = "Windows Me"
[blue]End Select

Case [/blue]VER_PLATFORM_WIN32_NT [green]' Windows NT, Windows 2000, Windows XP,
[/green][blue]Select Case [/blue].dwMajorVersion [green]' or Windows Server 2003 family.
[/green][blue]Case [/blue]3
getVersion = "Windows NT 3.51"
[blue]Case [/blue]4
getVersion = "Windows NT 4.0"
[blue]Case [/blue]5
[blue]Select Case [/blue].dwMinorVersion
[blue]Case [/blue]0
getVersion = "Windows 2000"
[blue]Case [/blue]1
getVersion = "Windows XP"
[blue]Case [/blue]2
getVersion = "Windows Server 2003"
[blue]End Select
End Select

Case Else
[/blue]getVersion = "Failed"

[blue]End Select

End With
End Function
[/blue]

Form...

[blue]Private Sub [/blue]Command1_Click()
MsgBox getVersion
[blue]End Sub
[/blue]
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top