1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
| Option Explicit
'API Windows pour version de Windows
Private Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFOEX) As Integer
'API Windows pour chercher si le système est en 64 bytes
Private Declare Function GetProcAddress Lib "kernel32" (ByVal hModule As Long, ByVal lpProcName As String) As Long
Private Declare Function GetModuleHandle Lib "kernel32" Alias "GetModuleHandleA" (ByVal lpModuleName As String) As Long
Private Declare Function GetCurrentProcess Lib "kernel32" () As Long
Private Declare Function IsWow64Process Lib "kernel32" (ByVal hProc As Long, bWow64Process As Boolean) As Long
Private Const VER_NT_WORKSTATION = 1 ' Le système d'exploitation est Windows 7, Windows Vista, Windows XP Professional, Windows XP Home Edition, or Windows 2000 Professional.
Private Type OSVERSIONINFOEX
dwOSVersionInfoSize As Long ' La taille de cette structure de données, en octets
dwMajorVersion As Long ' Le nombre de la version majeure du système d'exploitation
dwMinorVersion As Long ' Le nombre de la version mineure du système d'exploitation
dwBuildNumber As Long
dwPlatformId As Long
szCSDVersion As String * 128
wServicePackMajor As Integer
wServicePackMinor As Integer
wSuiteMask As Integer
wProductType As Byte ' Autre information supplémentaires sur le système et notamment pour VER_NT_WORKSTATION, wProductType = 1
wReserved As Byte
End Type
Public Function VersionWindows() As String
' Fonction pour identifier les versions de Windows [Windows XP, Seven 32 et 64 bytes]
Dim Os As OSVERSIONINFOEX
Dim Handle As Long
Dim Est64bit As Boolean
Dim Bytes As String
'Initialise la valeur à false : il n'y a pas Wow64 process
Est64bit = False
VersionWindows = "Système non prévu"
'On vérifie que la dll kernel32.dll contient bien une méthode IsWow64Process
Handle = GetProcAddress(GetModuleHandle("kernel32"), "IsWow64Process")
'Si la fonction IsWow64Process existe on l'utise pour déterminer si on est en 64 bytes
If Handle > 0 Then IsWow64Process GetCurrentProcess(), Est64bit
If Est64bit = False Then
Bytes = "32bytes"
Else
Bytes = "64bytes"
End If
Os.dwOSVersionInfoSize = Len(Os)
GetVersionExA Os
'On teste sur les versions de Windows
Select Case CStr(Os.dwMajorVersion & "." & Os.dwMinorVersion)
Case "5.1"
VersionWindows = "Windows XP"
Case "6.1"
If Os.wProductType = VER_NT_WORKSTATION Then VersionWindows = "Windows 7" & "-" & Bytes
End Select
End Function |
Partager