How to get the version of the Windows operating system
Many times we need to know the version of the Windows operating system, using the following API function can do.
Option Explicit
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (Lpversioninformation as osVersionInfo) as Long
Private Type osVersionInfo
dwOSVersionInfoSize as Long
dwMajorVersion as Long
dwMinorVersion as Long
dwBuildNumber as Long
dwPlatformId as Long
szCSDVersion As String * Maintenance string for PSS usage
Osname as String ' I add myself, the name of the operating system
End Type
' Get the version of the Windows operating system
' Osname in the OSVERSIONINFO structure returns the name of the operating system
Private Function getwindowsversion () as osVersionInfo
Dim ver as osVersionInfo
Ver.dwosversioninfosize = 148
GetVersionEx ver
With Ver
Select case. dwPlatformId
Case 1
Select case. dwMinorVersion
Case 0
. Osname = "Windows 95"
Case 10
. Osname = "Windows 98"
Case 90
. Osname = "Windows mellinnium"
End Select
Case 2
Select case. dwMajorVersion
Case 3
. Osname = "Windows NT 3.51"
Case 4
. Osname = "Windows NT 4.0"
Case 5
Select case. dwMinorVersion
Case 0
. Osname = "Windows 2000"
Case 1
. Osname = "Windows XP"
Case 2
. Osname = "Windows Server 2003"
End Select
End Select
Case Else
. Osname = "Failed"
End Select
End with
Getwindowsversion = ver
End Function
Private Sub Command1_Click ()
Dim ver as osVersionInfo
ver = getwindowsversion ()
With Ver
Debug.Print. Osname,. dwMajorVersion,. dwMinorVersion,. dwBuildNumber,. dwPlatformId,. szCSDVersion
End with
End Sub