How to get the version of the Windows operating system

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.