'****************************************************************************
'人人为我,我为人人
'枕善居汉化收藏整理
'发布日期:2007/08/20
'描 述:完全获取Windows操作系统的版本
'网 站:http://www.Mndsoft.com/ (VB6源码博客)
'网 站:http://www.VbDnet.com/ (VB.NET源码博客,主要基于.NET2005)
'e-mail :[email protected]
'e-mail :[email protected]
'OICQ :88382850
' 如果您有新的好的代码别忘记给枕善居哦!
'****************************************************************************
Option Explicit
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFOEX) As Long
Private Type OSVERSIONINFOEX
dwOSVersionInfoSize As Long
dwMajorVersion As Long
dwMinorVersion As Long
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
wServicePackMajor As Integer
wServicePackMinor As Integer
wSuiteMask As Integer
wProductType As Byte
wReserved As Byte
End Type
Private Const VER_PLATFORM_WIN32_NT As Long = 2
Private Const VER_PLATFORM_WIN32_WINDOWS As Long = 1
Private Const VER_PLATFORM_WIN32s As Long = 0
Private Const PRODUCT_UNLICENSED As Long = &HABCDABCD
Private Const PRODUCT_BUSINESS As Long = &H6
Private Const PRODUCT_BUSINESS_N As Long = &H10
Private Const PRODUCT_CLUSTER_SERVER As Long = &H12
Private Const PRODUCT_DATACENTER_SERVER As Long = &H8
Private Const PRODUCT_DATACENTER_SERVER_CORE As Long = &HC
Private Const PRODUCT_ENTERPRISE As Long = &H4
Private Const PRODUCT_ENTERPRISE_N As Long = &H1B
Private Const PRODUCT_ENTERPRISE_SERVER As Long = &HA
Private Const PRODUCT_ENTERPRISE_SERVER_CORE As Long = &HE
Private Const PRODUCT_ENTERPRISE_SERVER_IA64 As Long = &HF
Private Const PRODUCT_HOME_BASIC As Long = &H2
Private Const PRODUCT_HOME_BASIC_N As Long = &H5
Private Const PRODUCT_HOME_PREMIUM As Long = &H3
Private Const PRODUCT_HOME_PREMIUM_N As Long = &H1A
Private Const PRODUCT_HOME_SERVER As Long = &H13
Private Const PRODUCT_SERVER_FOR_SMALLBUSINESS As Long = &H18
Private Const PRODUCT_SMALLBUSINESS_SERVER As Long = &H9
Private Const PRODUCT_SMALLBUSINESS_SERVER_PREMIUM As Long = &H19
Private Const PRODUCT_STANDARD_SERVER As Long = &H7
Private Const PRODUCT_STANDARD_SERVER_CORE As Long = &HD
Private Const PRODUCT_STARTER As Long = &H8
Private Const PRODUCT_STORAGE_ENTERPRISE_SERVER As Long = &H17
Private Const PRODUCT_STORAGE_EXPRESS_SERVER As Long = &H14
Private Const PRODUCT_STORAGE_STANDARD_SERVER As Long = &H15
Private Const PRODUCT_STORAGE_WORKGROUP_SERVER As Long = &H16
Private Const PRODUCT_UNDEFINED As Long = &H0
Private Const PRODUCT_ULTIMATE As Long = &H1
Private Const PRODUCT_ULTIMATE_N As Long = &H1C
Private Const PRODUCT_WEB_SERVER As Long = &H11
Public Function GetWindowsVersion() As String
' 变量声明
Dim retOSVersionInf As OSVERSIONINFOEX
Dim retLng As Long
'结构尺寸
retOSVersionInf.dwOSVersionInfoSize = Len(retOSVersionInf)
'获取 Windows 版本
retLng = GetVersionEx(retOSVersionInf)
If retLng = 0 Then
GetWindowsVersion = "未知"
Exit Function
End If
With retOSVersionInf
If .dwPlatformId = VER_PLATFORM_WIN32_WINDOWS Then
Select Case .dwMajorVersion
Case 4
Select Case .dwMinorVersion
Case 0 ' Win 95
Select Case .szCSDVersion
Case "C" ' OSR2
GetWindowsVersion = "Windows 95 OSR2"
Case "B" ' OSR2
GetWindowsVersion = "Windows 95 OSR2"
Case Else
GetWindowsVersion = "Windows 95"
End Select
Case 10 ' Win 98
Select Case .szCSDVersion
Case "A" ' SE
GetWindowsVersion = "Windows 98 SE"
Case Else
GetWindowsVersion = "Windows 98"
End Select
Case 90 ' Win ME
GetWindowsVersion = "Windows ME"
End Select
End Select
ElseIf .dwPlatformId = VER_PLATFORM_WIN32_NT And .dwMajorVersion = 5 Then
Select Case .dwMinorVersion
Case 0 ' Win 2000
Select Case .wProductType
Case 1
Select Case .wSuiteMask
Case &H80 ' 数据中心
GetWindowsVersion = "Windows 2000 Data center"
Case &H2 ' 高级版本
GetWindowsVersion = "Windows 2000 Advanced"
Case Else
GetWindowsVersion = "Windows 2000"
End Select
End Select
Case 1 ' Win XP
Select Case .wProductType
Case 1
Select Case .wSuiteMask
Case &H0 ' Pro
GetWindowsVersion = "Windows XP Professional"
Case &H200 ' Home
GetWindowsVersion = "Windows XP Home"
Case Else ' XP
GetWindowsVersion = "Windows XP"
End Select
End Select
Case 2 ' Win Server 2003
Select Case .wProductType
Case 3
Select Case .wSuiteMask
Case &H2
GetWindowsVersion = "Windows Server 2003 Enterprise"
Case &H80
GetWindowsVersion = "Windows Server 2003 Data center"
Case &H400
GetWindowsVersion = "Windows Server 2003 Web Edition"
Case &H0
GetWindowsVersion = "Windows Server 2003 Standard"
Case Else
GetWindowsVersion = "Windows Server 2003"
End Select
End Select
End Select
If .wServicePackMajor > 0 Then
GetWindowsVersion = GetWindowsVersion & " Service Pack " & .wServicePackMajor & IIf(.wServicePackMinor > 0, "." & .wServicePackMinor, vbNullString)
End If
ElseIf .dwPlatformId = VER_PLATFORM_WIN32_NT And .dwMajorVersion = 6 Then
Select Case .dwMinorVersion
Case 0
Select Case .wProductType
Case PRODUCT_BUSINESS
GetWindowsVersion = "Business Edition"
Case PRODUCT_BUSINESS_N
GetWindowsVersion = "Business Edition (N)"
Case PRODUCT_CLUSTER_SERVER
GetWindowsVersion = "Cluster Server Edition"
Case PRODUCT_DATACENTER_SERVER
GetWindowsVersion = "Server Datacenter Edition (full installation)"
Case PRODUCT_DATACENTER_SERVER_CORE
GetWindowsVersion = "Server Datacenter Edition (core installation)"
Case PRODUCT_ENTERPRISE
GetWindowsVersion = "Enterprise Edition"
Case PRODUCT_ENTERPRISE_N
GetWindowsVersion = "Enterprise Edition (N)"
Case PRODUCT_ENTERPRISE_SERVER
GetWindowsVersion = "Server Enterprise Edition (full installation)"
Case PRODUCT_ENTERPRISE_SERVER_CORE
GetWindowsVersion = "Server Enterprise Edition (core installation)"
Case PRODUCT_ENTERPRISE_SERVER_IA64
GetWindowsVersion = "Server Enterprise Edition for Itanium-based Systems"
Case PRODUCT_HOME_BASIC
GetWindowsVersion = "Home Basic Edition"
Case PRODUCT_HOME_BASIC_N
GetWindowsVersion = "Home Basic Edition (N)"
Case PRODUCT_HOME_PREMIUM
GetWindowsVersion = "Home Premium Edition"
Case PRODUCT_HOME_PREMIUM_N
GetWindowsVersion = "Home Premium Edition (N)"
Case PRODUCT_HOME_SERVER
GetWindowsVersion = "Home Server Edition"
Case PRODUCT_SERVER_FOR_SMALLBUSINESS
GetWindowsVersion = "Server for Small Business Edition"
Case PRODUCT_SMALLBUSINESS_SERVER
GetWindowsVersion = "Small Business Server"
Case PRODUCT_SMALLBUSINESS_SERVER_PREMIUM
GetWindowsVersion = "Small Business Server Premium Edition"
Case PRODUCT_STANDARD_SERVER
GetWindowsVersion = "Server Standard Edition (full installation)"
Case PRODUCT_STANDARD_SERVER_CORE
GetWindowsVersion = "Server Standard Edition (core installation)"
Case PRODUCT_STARTER
GetWindowsVersion = "Starter Edition"
Case PRODUCT_STORAGE_ENTERPRISE_SERVER
GetWindowsVersion = "Storage Server Enterprise Edition"
Case PRODUCT_STORAGE_EXPRESS_SERVER
GetWindowsVersion = "Storage Server Express Edition"
Case PRODUCT_STORAGE_STANDARD_SERVER
GetWindowsVersion = "Storage Server Standard Edition"
Case PRODUCT_STORAGE_WORKGROUP_SERVER
GetWindowsVersion = "Storage Server Workgroup Edition"
Case PRODUCT_ULTIMATE
GetWindowsVersion = "Ultimate Edition"
Case PRODUCT_ULTIMATE_N
GetWindowsVersion = "Ultimate Edition (N)"
Case PRODUCT_UNDEFINED
GetWindowsVersion = "An unknown product"
Case PRODUCT_UNLICENSED
GetWindowsVersion = "Not activated product"
Case PRODUCT_WEB_SERVER
GetWindowsVersion = "Web Server Edition"
End Select
Select Case .wProductType
Case 1 ' Win Vista
GetWindowsVersion = "Windows Vista " & GetWindowsVersion
Case 3 ' Win Server 2008
GetWindowsVersion = "Windows Server 2008 " & GetWindowsVersion
Case Else
GetWindowsVersion = "Windows Vista " & GetWindowsVersion
End Select
If .wServicePackMajor > 0 Then
GetWindowsVersion = GetWindowsVersion & " Service Pack " & .wServicePackMajor & IIf(.wServicePackMinor > 0, "." & .wServicePackMinor, vbNullString)
End If
End Select
End If
GetWindowsVersion = GetWindowsVersion & " [Version: " & .dwMajorVersion & "." & .dwMinorVersion & "." & .dwBuildNumber & "]"
End With
End Function
相关文章参考:
※vb 关于commondialog的多选VB获取Windows操作系统所有版本
※VB 打开txt,bat,jpg 任意后缀程序
FSO对象新建、打开、保存文件
打开资源管理器并指定文件
※VB 打开文件夹,并选中指定的文件
VB手控Combobox的打开或收起
★VB部分相关文章推荐:★
※vb中line的用法[转]
※画图工具的VB实现
※VB 一个获得自己外网 IP 地址的程序代码
※VB程序中实现IP地址子网掩码网关DNS的更改 [转]
※在 VB 中应用 FSO 对象模型介绍(摘自网络)
※[转] Vb中FSO 对象的介绍
※VB 画坐标轴
※VB 二进制文件的操作
※[VB]BMP转JPGVB中KeyCode常数用法
※vb实时曲线的绘制和保存
※VB操作EXCEL
※vb初学回顾:最大公约数 最小公倍数 素数求取
※vb 关于窗口样式的API以及处理文本的API参考
※【引用】在VB6.0中实现弹出式菜单的几种方法
※【引用】URLDownloadToFile_VB下载文件!
※利用WinRar压缩和解压缩文件
※VB 剪切板
※VB实现指示窗口中拖动方框的程序
※VB绘制走动的表针
※如何用VB制作DLL文件
※【引用】VB修改IP地址
※VB多窗体退出代码
※[转]VB:如何检测到U盘的插拔(源代码)
※巧用SendMessage函数扩展Treeview功能
※vb中如何在任务管理器里面隐藏应用程序进程
※如何实现VB与EXCEL的无缝连接
※一个API方式存取日志文件的模块[VB]
※VB用记录集填充表格函数
※VB打开文本文件各种方法
※vb ClipBoard 剪切板应用(复制剪切粘贴)
※【引用】窗口处理技巧大全 vb(窗体控件)
※【转】 Md rd命令之VB
※vb:读写文本文件
※在vb中实现真正锁定的带自定义菜单的文本控件
※【引用】使用CommonDialog的ShowSave后如何判断是保存还是※取消?
※vb 关于commondialog的多选VB获取Windows操作系统所有版本
※vb UTF文本文件访问
※VB编程中的Unicode vs Ansi
※VB编PiView4注册机
※VB获取超过2G文件的大小
※比CopyMemory还要快的函数SuperCopyMemory
※VB:编程效率快步提高之:十七种可用一行代码完成的技巧
※VB画出来的五星红旗
※Qt第一印象——Qte与Qt