Zjištění typu Windows a informace o nich

Postup:
V modulu deklarujte:
Public Const VER_PLATFORM_WIN32s = 0
Public Const VER_PLATFORM_WIN32_WINDOWS = 1
Public Const VER_PLATFORM_WIN32_NT = 2

'windows typ OSVERSIONINFO
Public Type OSVERSIONINFO
    OSVSize As Long
'velikost v bitech této struktury
    dwVerMajor As Long 'NT 3.51 = 3; NT 4.0 = 4.
    dwVerMinor As Long 'NT 3.51 = 51; NT 4.0 = 0.
    dwBuildNumber As Long 'NT: build number OS,Win9x: build number OS v low-order word. High-order word obsahuje major & minor verze os.
   PlatformID As Long 'Identifikuje platformu operačního systému.
   szCSDVersion As String * 128 'NT: řetězec, např. "Service Pack 3", Win9x: další informace
End Type

'typ pro udržení získaných informací
Public Type RGB_WINVER
    PlatformID As Long
    VersionName As String
    VersionNo As String
    ServicePack As String
    BuildNo As String
End Type

Public Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long

Public Function GetWinVersion(WIN As RGB_WINVER) As String

#If Win32 Then
    Dim OSV As OSVERSIONINFO
    Dim r As Long
    Dim pos As Integer
    Dim sVer As String
    Dim sBuild As String
    OSV.OSVSize = Len(OSV)
    If GetVersionEx(OSV) = 1 Then
'PlatformId obsahuje hodnoty reprezentující OS
        WIN.PlatformID = OSV.PlatformID
        Select Case OSV.PlatformID
            Case VER_PLATFORM_WIN32s: WIN.VersionName = "Win32s"
            Case VER_PLATFORM_WIN32_WINDOWS:
'dwVerMinor říká, že se jedná o W95 nebo W98.
                Select Case OSV.dwVerMinor
                    Case 0: WIN.VersionName = "Windows 95"
                    Case Else: WIN.VersionName = "Windows 98"
                End Select
            Case VER_PLATFORM_WIN32_NT: WIN.VersionName = "Windows NT"
        End Select
      'Zjištění čísla verze
        WIN.VersionNo = OSV.dwVerMajor & "." & OSV.dwVerMinor
      'Zjištění buildu
        WIN.BuildNo = (OSV.dwBuildNumber And &HFFFF)
      'Další info. Ve Win9x, to může být jakýkoliv řetězec definovaný výrobcem.
      'V NT je to Service Pack.
        pos = InStr(OSV.szCSDVersion, Chr$(0))
        If pos Then
            WIN.ServicePack = Left$(OSV.szCSDVersion, pos - 1)
        End If
    End If
#Else
   'může to být pouze návratová hodnota bez podpory 32-bitů,
   'tedy jen Win3x
    WIN.VersionName = "Windows 3.x"
#End If

End Function

Public Function IsWinNT() As Boolean

#If Win32 Then
    Dim OSV As OSVERSIONINFO
    OSV.OSVSize = Len(OSV)
'api vrátí 1 pokud bylo volání úspěšné
    If GetVersionEx(OSV) = 1 Then 'PlatformId obsahuje hodnoty reprezentující OS, takže je - li VER_PLATFORM_WIN32_NT, vrátí True
        IsWinNT = OSV.PlatformID = VER_PLATFORM_WIN32_NT
    End If
#End If

End Function

Použití:
Dim WIN As RGB_WINVER
Call GetWinVersion(WIN)
V typu WIN je pak pro každou položku hodnota.
IsWinNT vrací buď True nebo False, podle OS

X=IsWinNT()

Zpět

Autor: The Bozena