VBA/Excel/Access/Word/Windows API/OSVERSIONINFO

Материал из VB Эксперт
Перейти к: навигация, поиск

Declaring the Type Structure OSVERSIONINFO in the General Declarations Section of the Module

 
Type OSVERSIONINFO
   dwOSVersionInfoSize As Long
   dwMajorVersion As Long
   dwMinorVersion As Long
   dwBuildNumber As Long
   dwPlatformId As Long
   strReserved As String * 128
End Type
Declare Function abGetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpOSInfo As OSVERSIONINFO) As Boolean
Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (ByRef lpVersionInformation As OSVERSIONINFO) As Long

Sub GetOSInfo()
    Dim OSInfo As OSVERSIONINFO
    Dim strMajorVersion As String
    Dim strMinorVersion As String
    Dim strBuildNumber As String
    Dim strPlatformId As String
    " Set the length member before you call GetVersionEx
    OSInfo.dwOSVersionInfoSize = Len(OSInfo)
    If GetVersionEx(OSInfo) Then
        strMajorVersion = OSInfo.dwMajorVersion
        strMinorVersion = OSInfo.dwMinorVersion
        strBuildNumber = OSInfo.dwBuildNumber And &HFFFF&
        strPlatformId = OSInfo.dwPlatformId
        Debug.Print "The Major Version Is:  " & strMajorVersion
        Debug.Print "The Minor Version Is:  " & strMinorVersion
        Debug.Print "The Build Number Is:  " & strBuildNumber
        Debug.Print "The Platform ID Is:   " & strPlatformId
    End If
End Sub