有哪个API可以检测操作系统的版本,如检验机器是用win98,win2k还是winxp,谢谢指教

解决方案 »

  1.   

    Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As LongPrivate Type OSVERSIONINFO
        dwOSVersionInfoSize As Long
        dwMajorVersion As Long
        dwMinorVersion As Long
        dwBuildNumber As Long
        dwPlatformId As Long
        szCSDVersion As String * 128
    End Type
    Private Sub Form_Load()
        Dim OSInfo As OSVERSIONINFO, PId As String
        '[email protected]
        'Set the graphical mode to persistent
        Me.AutoRedraw = True
        'Set the structure size
        OSInfo.dwOSVersionInfoSize = Len(OSInfo)
        'Get the Windows version
        Ret& = GetVersionEx(OSInfo)
        'Chack for errors
        If Ret& = 0 Then MsgBox "Error Getting Version Information": Exit Sub
        'Print the information to the form
        Select Case OSInfo.dwPlatformId
            Case 0
                PId = "Windows 32s "
            Case 1
                PId = "Windows 95/98"
            Case 2
                PId = "Windows NT "
        End Select
        Print "OS: " + PId
        Print "Win version:" + str$(OSInfo.dwMajorVersion) + "." + LTrim(str(OSInfo.dwMinorVersion))
        Print "Build: " + str(OSInfo.dwBuildNumber)
    End Sub
      

  2.   

    Public Declare Function GetVersionExA Lib "kernel32" (lpVersionInformation As OSVERSIONINFO) As Integer
    Public Type OSVERSIONINFO
       dwOSVersionInfoSize As Long
       dwMajorVersion As Long
       dwMinorVersion As Long
       dwBuildNumber As Long
       dwPlatformId As Long
       szCSDVersion As String * 128
    End Type
    Public Function GetVersion() As String
       Dim osinfo As OSVERSIONINFO
       Dim retvalue As Integer   osinfo.dwOSVersionInfoSize = 148
       osinfo.szCSDVersion = Space$(128)
       retvalue = GetVersionExA(osinfo)   With osinfo
        Select Case .dwPlatformId
            Case 1
                    Select Case .dwMinorVersion
                        Case 0
                            GetVersion = "Windows 95"
                        Case 10
                            GetVersion = "Windows 98"
                        Case 90
                            GetVersion = "Windows Mellinnium"
                    End Select
            Case 2
                    Select Case .dwMajorVersion
                        Case 3
                            GetVersion = "Windows NT 3.51"
                        Case 4
                            GetVersion = "Windows NT 4.0"
                        Case 5
                            If .dwMinorVersion = 0 Then
                                GetVersion = "Windows 2000"
                            Else
                                GetVersion = "Windows XP"
                            End If
                    End Select
             Case Else
                   GetVersion = "Failed"
        End Select
       End With
    End Function
      

  3.   

    GetVersion
    GetVersionEx
    就是这样