如何获得 Windows 操作系统的版本

如何获得 Windows 操作系统的版本

很多时候我们需要知道Windows操作系统的版本,使用下面这个API函数可以做到。

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 * 128 ' Maintenance string for PSS usage 
osName As String ' 我自己加的, 操作系统的名称 
End Type

' 获得 Windows 操作系统的版本 
' OSVERSIONINFO 结构中的 osName 返回操作系统的名称 
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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值