How to get the version of the Windows operating system

zhaozj2021-02-16  63

Many times we need to know the version of the Windows operating system, using the API function below.

Option expedition

Private Declare Function GetversionEx Lib "kernel32" Alias ​​"getversionExa" (LPVERSIONEXA "(LPVERSIONEXA" (LPVERSIONEXA "

Private Type OSVERSIONINFO dwOSVersionInfoSize As Long dwMajorVersion As Long dwMinorVersion As Long dwBuildNumber As Long dwPlatformId As Long szCSDVersion As String * 128 'Maintenance string for PSS usage osName As String' I added, the name of the operating system End Type

'Obtains the version of the Windows operating system' OSVERSIONINFO structure osName 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 .osn ame = "Windows XP" Case 2 .osName = "Windows Server 2003" End Select End Select Case Else .osName = "Failed" End Select End With GetWindowsVersion = verEnd FunctionPrivate Sub Command1_Click () Dim ver As OSVERSIONINFO ver = GetWindowsVersion () With Ver debug.print .osname, .dwmajorversion, .dwminorversion, .dwbuildnumber, .dwplatformID, .szcsdversion endhend Sub

* ------------------------------------------- *

* Please inform the author and indicate the source, 9CBS welcomes you! *

* Author: Lu Peipei (goodname008) ** E-mail: goodname008@163.com *

* Column: http://blog.9cbs.net/goodname008 *

* ------------------------------------------- *

转载请注明原文地址:https://www.9cbs.com/read-16958.html

New Post(0)