Make your own free website on Tripod.com

Home
Home

---Soumis par Dev Ashish---

Obtenir le nom du système d'exploitation.

Windows nous fourni la fonction API GetVersionEx pour nous permettre d'obtenir l'information pertinente relative au système d'exploitation. Le nom du OS (Operating System) et sa version, entre autres information, sont déduite de dwPlatformID, dwMajorVersion et de dwMinorVersion de la structure OSVERSIONINFO qui nous est retournée par GetVersionEx.

'   ********** Code Start **********
Private Type OSVERSIONINFO
    dwOSVersionInfoSize As Long
    dwMajorVersion As Long
    dwMinorVersion As Long
    dwBuildNumber As Long
    dwPlatformId As Long
    szCSDVersion As String * 128
End Type
 
Private Declare Function apiGetVersionEx Lib "kernel32" _
    Alias "GetVersionExA" _
    (lpVersionInformation As Any) _
    As Long
 
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2
 
Function fOSName() As String
Dim osvi As OSVERSIONINFO
Dim strOut As String
 
    osvi.dwOSVersionInfoSize = Len(osvi)
    If CBool(apiGetVersionEx(osvi)) Then
        With osvi
            If .dwPlatformId = VER_PLATFORM_WIN32_NT And _
                .dwMajorVersion = 5 Then
                    strOut = "Windows 2000 " & _
                        .dwMajorVersion & "." & .dwMinorVersion & _
                        " Build " & .dwBuildNumber
            End If
            If (.dwMajorVersion > 4 And _
                (.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS And _
                .dwMinorVersion > 0)) Then
                    strOut = "Windows 98"
            End If
            If (.dwPlatformId = VER_PLATFORM_WIN32_WINDOWS And _
                .dwMinorVersion = 0) Then
                    strOut = "Windows 95"
            End If
            If (.dwPlatformId = VER_PLATFORM_WIN32_NT And _
                .dwMajorVersion <= 4) Then
                strOut = "Windows NT " & _
                        .dwMajorVersion & "." & .dwMinorVersion & _
                        " Build " & .dwBuildNumber
            End If
        End With
    End If
    fOSName = strOut
End Function
'   ********** Code End **********