检测windows各版本完整代码

Option Explicit

Public Type OSVERSIONINFOEX
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128    ' Maintenance string for PSS usage
    wServicePackMajor As Integer
    wServicePackMinor As Integer
    wSuiteMask As Integer
    wProductType As Byte
    wReserved As Byte
End Type

Public 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
End Type

Public Const VER_PLATFORM_WIN32s = 0
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32_NT = 2

Public Const VER_NT_WORKSTATION = 1
Public Const VER_NT_DOMAIN_CONTROLLER = 2
Public Const VER_NT_SERVER = 3


Public Const VER_SERVER_NT = &H80000000
Public Const VER_WORKSTATION_NT = &H40000000
Public Const VER_SUITE_ENTERPRISE = &H2
Public Const VER_SUITE_DATACENTER = &H80
Public Const VER_SUITE_PERSONAL = &H200

Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFOEX) As Long Public Declare Function RegOpenKeyEx Lib "advapi32.dll" Alias "RegOpenKeyExA" (ByVal hKey As Long, ByVal lpSubKey As String, ByVal ulOptions As Long, ByVal samDesired As Long, phkResult As Long) As Long Public Declare Function RegQueryValueEx Lib "advapi32.dll" Alias "RegQueryValueExA" (ByVal hKey As Long, ByVal lpValueName As String, ByVal lpReserved As Long, lpType As Long, lpData As Any, lpcbData As Long) As Long Public Declare Function RegCloseKey Lib "advapi32.dll" (ByVal hKey As Long) As Long
Public Const HKEY_LOCAL_MACHINE = &H80000002
Public Const KEY_QUERY_VALUE = &H1

Public Function GetWinVer() As String      '调用函数
    Dim osi As OSVERSIONINFOEX, osi1 As OSVERSIONINFO, bOsVersionInfoEx As Boolean, strVer As String
    osi.dwOSVersionInfoSize = Len(osi)
    bOsVersionInfoEx = GetVersionEx(osi)
    If (bOsVersionInfoEx = 0) Then
        osi.dwOSVersionInfoSize = Len(osi1)
        Call GetVersionEx(osi)
    End If
    Select Case osi.dwPlatformId
        Case VER_PLATFORM_WIN32_NT:
            If (osi.dwMajorVersion <= 4) Then
strVer = "Microsoft Windows NT"
ElseIf (osi.dwMajorVersion = 5 And osi.dwMinorVersion = 0) Then
strVer = "Microsoft Windows 2000"
ElseIf (osi.dwMajorVersion = 5 And osi.dwMinorVersion = 1) Then
strVer = "Microsoft Windows XP"
End If

If (bOsVersionInfoEx) Then
If (osi.wProductType = VER_NT_WORKSTATION) Then
If (osi.wSuiteMask And VER_SUITE_PERSONAL) Then
strVer = strVer & " Personal"
Else
strVer = strVer & " Professional"
End If
ElseIf (osi.wProductType = VER_NT_SERVER) Then
If (osi.wSuiteMask And VER_SUITE_DATACENTER) Then
strVer = strVer & " DataCenter Server"
ElseIf (osi.wSuiteMask And VER_SUITE_ENTERPRISE) Then
strVer = strVer & " Advanced Server"
Else
strVer = strVer & " Server"
End If
End If
Else
Dim hKey As Long
Dim szProductType As String * 80
Dim dwBufLen As Long

Call RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SYSTEM/CurrentControlSet/Control/ProductOptions", 0, KEY_QUERY_VALUE, hKey)
Call RegQueryValueEx(hKey, "ProductType", 0&, 0&, ByVal szProductType, dwBufLen)
Call RegCloseKey(hKey)
If (szProductType = "WINNT") Then
strVer = strVer & " Professional"
ElseIf (szProductType = "LANMANNT") Then
strVer = strVer & " Server"
ElseIf (szProductType = "SERVERNT") Then
strVer = strVer & " Advanced Server"
End If
End If


If (osi.dwMajorVersion <= 4) Then
strVer = strVer & " Version" & CStr(osi.dwMajorVersion) & "." & CStr(osi.dwMinorVersion) & " " & CStr(osi.szCSDVersion) & " (Build " & CStr((osi.dwBuildNumber And &HFFFF)) & ")"
Else
strVer = strVer & " " & CStr(Left(osi.szCSDVersion, InStr(1, osi.szCSDVersion, Chr(0)) - 1)) & "(Build " & CStr(osi.dwBuildNumber And &HFFFF) & ")"
End If

Case VER_PLATFORM_WIN32_WINDOWS:
If (osi.dwMajorVersion = 4 And osi.dwMinorVersion = 0) Then
strVer = "Microsoft Windows 95"
If (Mid(osi.szCSDVersion, 2, 1) = "C" Or Mid(osi.szCSDVersion, 2, 1) = "B") Then
strVer = strVer & " OSR2"
End If
ElseIf (osi.dwMajorVersion = 4 And osi.dwMinorVersion = 10) Then
strVer = strVer & "Microsoft Windows 98"
If (Mid(osi.szCSDVersion, 2, 1) = "A") Then
strVer = strVer & " SE"
End If
ElseIf (osi.dwMajorVersion = 4 And osi.dwMinorVersion = 90) Then
strVer = strVer & "Microsoft Windows Me"
End If
Case VER_PLATFORM_WIN32s:
strVer = "Microsoft Win32s"
Case Else:
strVer = ""
End Select
GetWinVer = strVer
End Function
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值