PLC论坛-全力打造可编程控制器专业技术论坛

 找回密码
 注册哦

QQ登录

只需一步,快速开始

微信扫码登录

查看: 1728|回复: 1

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

[复制链接]
发表于 2006-4-23 22:09:00 | 显示全部楼层 |阅读模式

很多时候我们需要知道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
dwPlatform i d 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
s el e c t Case .dwPlatform i d
Case 1
s el e c t Case .dwMinorVersion
Case 0
.osName = "Windows 95"
Case 10
.osName = "Windows 98"
Case 90
.osName = "Windows Mellinnium"
End s el e c t
Case 2
s el e c t Case .dwMajorVersion
Case 3
.osName = "Windows NT 3.51"
Case 4
.osName = "Windows NT 4.0"
Case 5
s el e c t Case .dwMinorVersion
Case 0
.osName = "Windows 2000"
Case 1
.osName = "Windows XP"
Case 2
.osName = "Windows Server 2003"
End s el e c t
End s el e c t
Case Else
.osName = "Failed"
End s el e c t
End With
GetWindowsVersion = ver
End Function

Private Sub Command1_Click()
Dim ver As OSVERSIONINFO
ver = GetWindowsVersion()
With ver
Debug.Print .osName, .dwMajorVersion, .dwMinorVersion, .dwBuildNumber, .dwPlatform i d, .szCSDVersion
End With
End Sub


[此贴子已经被作者于2007-1-14 23:12:06编辑过]
回复

使用道具 举报

发表于 2007-5-16 20:32:00 | 显示全部楼层
学习中
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册哦

本版积分规则

QQ|小黑屋|手机版|Archiver|PLC技术网-PLC论坛 ( 粤ICP备17165530号 )|网站地图

GMT+8, 2024-4-29 00:16 , Processed in 0.049297 second(s), 24 queries .

快速回复 返回顶部 返回列表