对不起,有的手误,现在更正:Option ExplicitPrivate Type OSVERSIONINFO
        dwOSVersionInfoSize As Long
        dwMajorVersion As Long
        dwMinorVersion As Long
        dwBuildNumber As Long
        dwPlatformId As Long
        szCSDVersion As String * 128  '  Maintenance string for PSS usage
End Type
Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
Private Const VER_PLATFORM_WIN32s = 0
Private Const VER_PLATFORM_WIN32_WINDOWS = 1
Private Const VER_PLATFORM_WIN32_NT = 2Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
Private Const SM_CLEANBOOT = 67
Private Const SM_DEBUG = 22
Private Const SM_SLOWMACHINE = 73Private m_udtVersionInfo As OSVERSIONINFO
Private m_lngRet As LongPublic Enum enumSystemStatus
    ssNormal = 0 '"正常模式"
    ssSafeMode = 1 '"安全模式"
    ssSafeModeWithNetwork = 2 '"带网络支持的安全模式"
    ssDebug = 3 '"Windows 排错模式"
    ssSlowMachine = 4 '"这台机器太慢以致不能流畅的运行Windows"
End EnumPublic Enum enumSystemPlatform
    spWindows = 1
    spWinNT = 2
End EnumPrivate Sub InitializeSystemInfo()
    
    m_udtVersionInfo.dwOSVersionInfoSize = 148
    
    m_lngRet = GetVersionEx(m_udtVersionInfo)
    
End Sub
Public Function GetSystemPlatform() As enumSystemPlatform
    
    Select Case m_udtVersionInfo.dwPlatformId
        Case VER_PLATFORM_WIN32_WINDOWS
            GetSystemPlatform = spWindows
        Case VER_PLATFORM_WIN32_NT
            GetSystemPlatform = spWinNT
        Case Else
            GetSystemPlatform = spWindows
    End Select
    
End Function
Public Function GetSystemStatus() As enumSystemStatus    If GetSystemMetrics(SM_CLEANBOOT) = 0 Then
        GetSystemStatus = ssNormal '"正常模式"
    ElseIf GetSystemMetrics(SM_CLEANBOOT) = 1 Then
        GetSystemStatus = ssSafeMode '= "安全模式"
    ElseIf GetSystemMetrics(SM_CLEANBOOT) = 2 Then
        GetSystemStatus = ssSafeModeWithNetwork '"带网络支持的安全模式"
    ElseIf GetSystemMetrics(SM_DEBUG) Then
        GetSystemStatus = ssDebug '"Windows 排错模式"
    ElseIf GetSystemMetrics(SM_SLOWMACHINE) Then
        GetSystemStatus = ssSlowMachine '"这台机器太慢以致不能流畅的运行Windows"
    End IfEnd Function
Public Function GetSystemMajorVersion() As String
    
    GetSystemMajorVersion = m_udtVersionInfo.dwMajorVersion '& "." & m_udtVersionInfo.dwMinorVersion & " Build " & (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
Public Function GetSystemMinorVersion() As String
    
    GetSystemMinorVersion = m_udtVersionInfo.dwMinorVersion & " Build " & (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
Public Function GetSystemBuildVersion() As Long
    
    GetSystemBuildVersion = (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
Private Sub Class_Initialize()
    
    InitializeSystemInfo
    
End Sub

解决方案 »

  1.   

    如何知道操作系统是Win98还是WinXP
      

  2.   

    Win95:m_udtVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS And m_udtVersionInfo.dwMajorVersion = 4Win98:m_udtVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_WINDOWS And m_udtVersionInfo.dwMajorVersion = 4 And osvi.dwMinorVersion > 0Win2000:m_udtVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT And m_udtVersionInfo.dwMajorVersion = 5WinXp:m_udtVersionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT And m_udtVersionInfo.dwMajorVersion = 5 And  osvi.dwMinorVersion > 0
      

  3.   

    winNT/2000/xp 也能分清么?我只写过分清 98 / nt / 2000  的加上 XP 就不知道能不能分清了,关键是分清XP 和 2000
      

  4.   

    VBA。EVENT
    好象是把,反正是E开头的函数,可以实现部分功能,如果要求不搞,可以考虑用这个!
      

  5.   

    大家来学.netImports System
    Imports System.Environment
    Public Module modmain
       Sub Main()
          'The KPD-Team 2001
          'URL: http://www.allapi.net/dotnet/
          'E-Mail: [email protected]
          Console.WriteLine("Operating System Platform ID: " _
             + OSVersion.Platform.ToString)
          Console.WriteLine("Version: " + _
             OSVersion.Version.Major.ToString + "." _
             + OSVersion.Version.Minor.ToString)
       End Sub
    End Module
      

  6.   

    对不起,刚才看了一下Microsoft的Platform SDK(November 2001 ),判断不同的版本,应该这样:http://msdn.microsoft.com/library/en-us/sysinfo/sysinfo_92jy.asp?frame=true
      

  7.   

    最新版本:Option ExplicitPrivate Type OSVERSIONINFOEX
        dwOSVersionInfoSize As Long
        dwMajorVersion As Long
        dwMinorVersion As Long
        dwBuildNumber As Long
        dwPlatformId As Long
        szCSDVersion As String * 128  '  Maintenance string for PSS usage
        wServicePackMajor As Integer
        wServicePackMinor As Integer
        wSuiteMask As Integer
        wProductType As String
        wReserved As String
    End Type
    Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFOEX) As Long
    Private Const VER_PLATFORM_WIN32s = 0
    Private Const VER_PLATFORM_WIN32_WINDOWS = 1
    Private Const VER_PLATFORM_WIN32_NT = 2Private Const VER_SUITE_BACKOFFICE = 0 'Microsoft BackOffice components are installed.
    Private Const VER_SUITE_BLADE = 1 'Windows .NET Web Server is installed.
    Private Const VER_SUITE_DATACENTER = 2 ' Windows 2000 or Windows .NET Datacenter Server is installed.
    Private Const VER_SUITE_ENTERPRISE = 3 ' Windows 2000 Advanced Server or Windows .NET Enterprise Server is installed.
    Private Const VER_SUITE_PERSONAL = 4 '  Windows XP Home Edition is installed.
    Private Const VER_SUITE_SMALLBUSINESS = 5 ' Microsoft Small Business Server is installed.
    Private Const VER_SUITE_SMALLBUSINESS_RESTRICTED = 6 ' Microsoft Small Business Server is installed with the restrictive client license in force.
    Private Const VER_SUITE_TERMINAL = 7 ' Terminal Services is installed.Private Const VER_NT_WORKSTATION = 0 'The system is running Windows NT 4.0 Workstation, Windows 2000 Professional, Windows XP Home Edition, or Windows XP Professional.
    Private Const VER_NT_DOMAIN_CONTROLLER = 1 'The system is a domain controller.
    Private Const VER_NT_SERVER = 2 'The system is a server.Private Declare Function GetSystemMetrics Lib "user32" (ByVal nIndex As Long) As Long
    Private Const SM_CLEANBOOT = 67
    Private Const SM_DEBUG = 22
    Private Const SM_SLOWMACHINE = 73Private m_udtVersionInfo As OSVERSIONINFOEX
    Private m_blnRet As BooleanPublic Enum enumSystemStatus
        ssNormal = 0 '"正常模式"
        ssSafeMode = 1 '"安全模式"
        ssSafeModeWithNetwork = 2 '"带网络支持的安全模式"
        ssDebug = 3 '"Windows 排错模式"
        ssSlowMachine = 4 '"这台机器太慢以致不能流畅的运行Windows"
    End EnumPublic Enum enumSystemPlatform
        spWin32 = 0
        spWindows = 1
        spWinNT = 2
    End EnumPrivate Sub InitializeSystemInfo()
        
        m_udtVersionInfo.dwOSVersionInfoSize = 148
        
        m_blnRet = CBool(GetVersionEx(m_udtVersionInfo))
        
    End Sub
    Public Function GetSystemPlatform() As enumSystemPlatform
        
        Select Case m_udtVersionInfo.dwPlatformId
            Case VER_PLATFORM_WIN32_WINDOWS
                GetSystemPlatform = spWindows
            Case VER_PLATFORM_WIN32_NT
                GetSystemPlatform = spWinNT
            Case Else
                GetSystemPlatform = spWin32
        End Select
        
    End Function
    Public Function GetSystemVersionEx() As String
                
        With m_udtVersionInfo
            Select Case .dwPlatformId
                Case VER_PLATFORM_WIN32_WINDOWS
                    If .dwMajorVersion = 4 & .dwMinorVersion = 0 Then
                        GetSystemVersionEx = "Microsoft Windows 95"
                         
                        If Mid(.szCSDVersion, 1, 1) = "C" Or Mid(.szCSDVersion, 1, 1) = "B" Then
                           GetSystemVersionEx = GetSystemVersionEx & " OSR2"
                        End If
                    ElseIf .dwMajorVersion = 4 And .dwMinorVersion = 10 Then
                        GetSystemVersionEx = "Microsoft Windows 98"
                        If Mid(.szCSDVersion, 1, 1) = "A" Then
                           GetSystemVersionEx = GetSystemVersionEx & " SE"
                        End If
                    ElseIf .dwMajorVersion = 4 And .dwMinorVersion = 90 Then
                        GetSystemVersionEx = "Microsoft Windows Millennium Edition"
                    Else
                    End If
                             
                Case VER_PLATFORM_WIN32_NT
                    If .dwMajorVersion <= 4 Then
                        GetSystemVersionEx = "Microsoft Windows NT"
                    ElseIf .dwMajorVersion = 5 And .dwMinorVersion = 0 Then
                        GetSystemVersionEx = "Microsoft Windows 2000"
                    Else
                        If m_blnRet Then
                            If .wProductType = VER_NT_WORKSTATION Then                            If .dwMajorVersion = 5 And .dwMinorVersion = 1 Then
                                    GetSystemVersionEx = "Microsoft Windows XP"                            ElseIf .wSuiteMask And VER_SUITE_PERSONAL Then
                                    GetSystemVersionEx = "Home Edition"
                                Else
                                    GetSystemVersionEx = "Professional"
                                End If
                            ElseIf .wProductType = VER_NT_SERVER Then
                               If .dwMajorVersion = 5 And .dwMinorVersion = 1 Then
                                  GetSystemVersionEx = "Microsoft Windows .NET"
                               ElseIf .wSuiteMask And VER_SUITE_DATACENTER Then
                                  GetSystemVersionEx = "DataCenter Server"
                               ElseIf .wSuiteMask And VER_SUITE_ENTERPRISE Then
                                  If .dwMajorVersion = 4 Then
                                     GetSystemVersionEx = "Advanced Server"
                                  Else
                                     GetSystemVersionEx = "Enterprise Server"
                                  End If
                               ElseIf .wSuiteMask = VER_SUITE_BLADE Then
                                  GetSystemVersionEx = "Web Server"
                               Else
                                  GetSystemVersionEx = "Server"
                               End If
                            Else
                            End If
                        Else
                        End If
                    End If
                Case Else
            End Select
        End With
        
    End Function
    Public Function GetSystemStatus() As enumSystemStatus    If GetSystemMetrics(SM_CLEANBOOT) = 0 Then
            GetSystemStatus = ssNormal '"正常模式"
        ElseIf GetSystemMetrics(SM_CLEANBOOT) = 1 Then
            GetSystemStatus = ssSafeMode '= "安全模式"
        ElseIf GetSystemMetrics(SM_CLEANBOOT) = 2 Then
            GetSystemStatus = ssSafeModeWithNetwork '"带网络支持的安全模式"
        ElseIf GetSystemMetrics(SM_DEBUG) Then
            GetSystemStatus = ssDebug '"Windows 排错模式"
        ElseIf GetSystemMetrics(SM_SLOWMACHINE) Then
            GetSystemStatus = ssSlowMachine '"这台机器太慢以致不能流畅的运行Windows"
        End IfEnd Function
    Public Function GetSystemMajorVersion() As String
        
        GetSystemMajorVersion = m_udtVersionInfo.dwMajorVersion '& "." & m_udtVersionInfo.dwMinorVersion & " Build " & (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
    Public Function GetSystemMinorVersion() As String
        
        GetSystemMinorVersion = m_udtVersionInfo.dwMinorVersion & " Build " & (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
    Public Function GetSystemBuildVersion() As Long
        
        GetSystemBuildVersion = (m_udtVersionInfo.dwBuildNumber And &HFFFF&)End Function
    Private Sub Class_Initialize()
        
        InitializeSystemInfo
        
    End Sub参考:
    http://msdn.microsoft.com/library/en-us/sysinfo/sysinfo_92jy.asp?frame=true
      

  8.   

    好厉害哦!可是用 SysInfo 不行吗?
      

  9.   

    刚才根据Platform SDK的例子,在VB里面重新写了一遍,希望对大家有帮助
      

  10.   

    to:ASCIIMan(sFileName as String) 如果使用简单的代码可以实现,为什么还要用控件呢?使用控件只会额外增加你的程序的大小啊!说得不客气的话:如果永远只会用现成的控件,而不懂得去编写属于自己的代码的方法,这的确是VB的悲哀。
      

  11.   

    to enmity(灵感之源) :
    非常可惜,能诉我如何使用吗?
      

  12.   

    to:cy_nwau(小人物) 新建一个类模块,命名为cSystemVersionInfo使用:先声明:private m_ucmSystemVersionInfo as new cSystemVersionInfo获取具体系统版本信息:msgbox GetSystemVersionEx
      

  13.   

    to:cy_nwau(小人物) 对不起,有点手误,现在更正:
    新建一个类模块,命名为cSystemVersionInfo使用:先声明:private m_ucmSystemVersionInfo as new cSystemVersionInfo获取具体系统版本信息:msgbox m_ucmSystemVersionInfo.GetSystemVersionEx