VB 获取操作系统版本 (模块)

Option Explicit

Public OSNameAs String'操作系统名称(简称),方便程序控制时根据操作系统取值

Public Type OSVERSIONINFO
    dwOSVersionInfoSize
AsLong
    dwMajorVersion
AsLong
    dwMinorVersion
AsLong
    dwBuildNumber
AsLong
    dwPlatformId
AsLong
    szCSDVersion
AsString * 128
    wServicePackMajor
AsInteger
    wServicePackMinor
AsInteger
    wSuiteMask
AsInteger
    wProductType
AsByte
    wReserved
AsByte
End Type

Public Declare Function GetVersionExLib "kernel32"Alias "GetVersionExA" (lpVersionInformationAs OSVERSIONINFO)As Long

' 获得 Windows 操作系统的名称,returnType决定返回的方式,值为0时,返回简称,否则返回全称
Public Function GetWindowsVersion(ByVal returnTypeAs Integer)As String
   
Dim ver As OSVERSIONINFO, retLngAs Long, osAs String
    ver.dwOSVersionInfoSize
=Len(ver)
    GetVersionEx ver
   
'    retLng = GetVersionEx(ver)
'
    If retLng = 0 Then
'
        os = "Unknown System Version!"
'
        Exit Function
'
    End If
   
   
With ver
       
SelectCase .dwPlatformId
           
Case1
               
SelectCase .dwMinorVersion
                   
Case0
                       
If returnType= 0Then
                            os
="Windows 95"
                       
Else
                           
SelectCase .szCSDVersion
                               
Case"C"
                                    os
="Windows 95 OSR2"
                               
Case"B"
                                    os
="Windows 95 OSR2"
                               
CaseElse
                                    os
="Windows 95"
                           
EndSelect
                       
EndIf
                   
Case10
                       
If returnType= 0Then
                            os
="Windows 98"
                       
Else
                           
SelectCase .szCSDVersion
                               
Case"A"
                                    os
="Windows 98 SE"
                               
CaseElse
                                    os
="Windows 98"
                           
EndSelect
                       
EndIf
                   
Case90
                       
If returnType= 0Then
                            os
="Windows Me"
                       
Else
                            os
="Windows Millennium Edition"
                       
EndIf
               
EndSelect
           
Case2
               
SelectCase .dwMajorVersion
                   
Case3
                        os
="Windows NT 3.51"
                   
Case4
                        os
="Windows NT 4.0"
                   
Case5
                       
SelectCase .dwMinorVersion
                           
Case0
                               
If returnType= 0Then
                                    os
="Windows 2000"
                               
Else
                                   
SelectCase .wSuiteMask
                                       
Case&H80
                                            os
="Windows 2000 Data center"
                                       
Case&H2
                                            os
="Windows 2000 Advanced"
                                       
CaseElse
                                            os
="Windows 2000"
                                   
EndSelect
                               
EndIf
                           
Case1
                               
If returnType= 0Then
                                    os
="Windows XP"
                               
Else
                                   
SelectCase .wSuiteMask
                                       
Case&H0
                                            os
="Windows XP Professional"
                                       
Case&H200
                                            os
="Windows XP Home"
                                       
CaseElse
                                            os
="Windows XP"
                                   
EndSelect
                               
EndIf
                           
Case2
                               
If returnType= 0Then
                                    os
="Windows Server 2003"
                               
Else
                                   
SelectCase .wSuiteMask
                                       
Case&H2
                                            os
="Windows Server 2003 Enterprise"
                                       
Case&H80
                                            os
="Windows Server 2003 Data center"
                                       
Case&H400
                                            os
="Windows Server 2003 Web Edition"
                                       
Case&H0
                                            os
="Windows Server 2003 Standard"
'                                        Case &H112
'
                                            os = "Windows Server 2003 R2 Enterprise"
                                        Case Else
                                            os
="Windows Server 2003"
                                   
EndSelect
                               
EndIf
                       
EndSelect
                       
If returnType<> 0And .wServicePackMajor> 0Then
                            os
= os& " Service Pack" & .wServicePackMajor& IIf(.wServicePackMinor> 0,"."& .wServicePackMinor, vbNullString)
                       
EndIf
                   
Case6
                       
If returnType<> 0Then
                           
SelectCase .wProductType
                               
Case&H6
                                    os
="Business Edition"
                               
Case&H10
                                    os
="Business Edition (N)"
                               
Case&H12
                                    os
="Cluster Server Edition"
                               
Case&H8
                                    os
="Server Datacenter Edition (full installation)"
                               
Case&HC
                                    os
="Server Datacenter Edition (core installation)"
                               
Case&H4
                                    os
="Enterprise Edition"
                               
Case&H1B
                                    os
="Enterprise Edition (N)"
                               
Case&HA
                                    os
="Server Enterprise Edition (full installation)"
                               
Case&HE
                                    os
="Server Enterprise Edition (core installation)"
                               
Case&HF
                                    os
="Server Enterprise Edition for Itanium-based Systems"
                               
Case&H2
                                    os
="Home Basic Edition"
                               
Case&H5
                                    os
="Home Basic Edition (N)"
                               
Case&H3
                                    os
="Home Premium Edition"
                               
Case&H1A
                                    os
="Home Premium Edition (N)"
                               
Case&H13
                                    os
="Home Server Edition"
                               
Case&H18
                                    os
="Server for Small Business Edition"
                               
Case&H9
                                    os
="Small Business Server"
                               
Case&H19
                                    os
="Small Business Server Premium Edition"
                               
Case&H7
                                    os
="Server Standard Edition (full installation)"
                               
Case&HD
                                    os
="Server Standard Edition (core installation)"
                               
Case&H8
                                    os
="Starter Edition"
                               
Case&H17
                                    os
="Storage Server Enterprise Edition"
                               
Case&H14
                                    os
="Storage Server Express Edition"
                               
Case&H15
                                    os
="Storage Server Standard Edition"
                               
Case&H16
                                    os
="Storage Server Workgroup Edition"
                               
Case&H1
                                    os
="Ultimate Edition"
                               
Case&H1C
                                    os
="Ultimate Edition (N)"
                               
Case&H0
                                    os
="An unknown product"
                               
Case&HABCDABCD
                                    os
="Not activated product"
                               
Case&H11
                                    os
="Web Server Edition"
                           
EndSelect
                       
EndIf
                       
SelectCase .dwMinorVersion
                           
Case0
                               
SelectCase .wProductType
                                   
Case3
                                       
If returnType= 0Then
                                            os
="Windows Server 2008"
                                       
Else
                                            os
="Windows Server 2008" & os
                                       
EndIf
                                   
CaseElse
                                       
If returnType= 0Then
                                            os
="Windows Vista"
                                       
Else
                                            os
="Windows Vista " & os
                                       
EndIf
                               
EndSelect
                           
Case1
                               
SelectCase .wProductType
                                   
Case3
                                       
If returnType= 0Then
                                            os
="Windows Server 2008 R2"
                                       
Else
                                            os
="Windows Server 2008 R2"& os
                                       
EndIf
                                   
CaseElse
                                       
If returnType= 0Then
                                            os
="Windows 7"
                                       
Else
                                            os
="Windows 7 " & os
                                       
EndIf
                               
EndSelect
                       
EndSelect
                       
If returnType<> 0And .wServicePackMajor> 0Then
                            os
= os& " Service Pack" & .wServicePackMajor& IIf(.wServicePackMinor> 0,"."& .wServicePackMinor, vbNullString)
                       
EndIf
               
EndSelect
           
CaseElse
                os
="Unknown System Version!"
       
End Select
   
If returnType<> 0Then os = os &" [Version: " & .dwMajorVersion& "."& .dwMinorVersion& "."& .dwBuildNumber& "]"
   
End With
    GetWindowsVersion
= os
End Function

'返回获取本地连接属性的方式
'
Vista及Win7下 GetDetailsOf(FolderItem, 2) 获取的值类似于:“Marvell Yukon 88E8056 PCI-E Gigabit Ethernet Controller”,对应XP、2000及2003下的GetDetailsOf(FolderItem, 3)
'
Vista及Win7下 GetDetailsOf(FolderItem, 1) 获取的值为本地连接状态,为“网络”时说明正常,对应XP、2000及2003下的GetDetailsOf(FolderItem, 2)
Public Function getAdapterStatusType()As Integer
   
Select Case OSName
       
Case "Windows Vista","Windows Server 2008","Windows 7","Windows Server 2008 R2"
            getAdapterStatusType
=2
       
Case Else
            getAdapterStatusType
=3
   
End Select
End Function

 


'返回获取本地连接属性的方式
'
Vista及Win7下 GetDetailsOf(FolderItem, 2) 获取的值类似于:“Marvell Yukon 88E8056 PCI-E Gigabit Ethernet Controller”,对应XP、2000及2003下的GetDetailsOf(FolderItem, 3)
'
Vista及Win7下 GetDetailsOf(FolderItem, 1) 获取的值为本地连接状态,为“网络”时说明正常,对应XP、2000及2003下的GetDetailsOf(FolderItem, 2)
Public Function getAdapterStatusType()As Integer
   
Select Case OSName
       
Case "Windows Vista","Windows Server 2008","Windows 7","Windows Server 2008 R2"
            getAdapterStatusType
=2
       
Case Else
            getAdapterStatusType
=3
   
End Select
End Function

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

蓝图

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值