'引用控件 Microsoft SysInfo Control 6.0
Dim OS As StringWith SysInfo1
    Select Case .OSPlatform
        Case 0: OS = "Win32"
        Case 1:
            Select Case .OSVersion
                Case 4: OS = "Win 95"
                Case 4.1: OS = "Win 98"
                Case 4.9: OS = "Wim Me"
            End Select
        Case 2:
            Select Case .OSVersion
                Case 4: OS = "Win NT"
                Case 5: OS = "Win 2000"
                Case 6: OS = "Win XP"
            End Select
    End Select
    
    MsgBox "Build:" & .OSBuild & vbNewLine & _
        "Platform:" & OS & "(" & .OSPlatform & ")" & vbNewLine & _
        "Version:" & .OSVersion
End With

解决方案 »

  1.   

    use these api
    void CLakerDlg::DetectSystemVersion(void)
    {
        OSVERSIONINFOEX osvi;
        BOOL bOsVersionInfoEx;
        //char * s = new char[ 100 ];
        memset( sql, 0, 100 );
    #define a( t ) strcat( sql, t )    ZeroMemory( &osvi, sizeof( OSVERSIONINFOEX ) );
        osvi.dwOSVersionInfoSize = sizeof( OSVERSIONINFOEX );
        a( "    -->" );    if( !( bOsVersionInfoEx = GetVersionEx( ( OSVERSIONINFO * ) &osvi ) ) )
        {
            osvi.dwOSVersionInfoSize = sizeof ( OSVERSIONINFO );
            if ( !GetVersionEx ( ( OSVERSIONINFO * ) &osvi) )
            {
                //delete []s;
                return;
            }
        }
        switch (osvi.dwPlatformId)
        {
        case VER_PLATFORM_WIN32_NT:
            if( osvi.dwMajorVersion <= 4 )
                a( "Microsoft Windows NT " );
            if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0 )
                a( "Microsoft Windows 2000 " );
            if( osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1 )
                a( "Microsoft Windows XP " );
            if( bOsVersionInfoEx )
            {
                if ( osvi.wProductType == VER_NT_WORKSTATION )
                {
                    if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
                        a( "Personal " );
                    else
                        a( "Professional " );
                }
                else if ( osvi.wProductType == VER_NT_SERVER )
                {
                    if( osvi.wSuiteMask & VER_SUITE_DATACENTER )
                        a ( "DataCenter Server " );
                    else if(  osvi.wSuiteMask & VER_SUITE_ENTERPRISE  )
                        a ( "Advanced Server " );
                    else
                        a ( "Server " );
                }
            }
            else
            {
                HKEY hKey;
                char szProductType[80];
                DWORD dwBufLen;            RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Control\\ProductOptions", 0, KEY_QUERY_VALUE, &hKey );
                RegQueryValueEx( hKey, "ProductType", NULL, NULL, ( LPBYTE )szProductType, &dwBufLen );
                RegCloseKey( hKey );
                if( lstrcmpi( "WINNT", szProductType ) == 0 )
                    a( "Professional " );
                if( lstrcmpi( "LANMANNT", szProductType ) == 0 )
                    a(  "Server "  );
                if( lstrcmpi( "SERVERNT", szProductType ) == 0 )
                    a( "Advanced Server " );
            }        if (  osvi.dwMajorVersion <= 4  )
            {
                CString s0;
                s0.Format( "version %d.%d %s ( Build %d )", osvi.dwMajorVersion, osvi.dwMinorVersion, osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF );
                a( ( LPCTSTR )s0 );
            }
            else
            { 
                CString s1;
                s1.Format( "%s ( Build %d )", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF );
                a( ( LPCTSTR )s1 );
            }
            break;    case VER_PLATFORM_WIN32_WINDOWS:        if ( osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0 )
            {
                a( "Microsoft Windows 95 " );
                if ( osvi.szCSDVersion[ 1 ] == 'C' || osvi.szCSDVersion[ 1 ] == 'B'  )
                    a( "OSR2 "  );
            } 
            if ( osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10 )
            {
                a( "Microsoft Windows 98 " );
                if ( osvi.szCSDVersion[1] == 'A')
                a( "SE "  );
            } 
            if ( osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90 )
            {
                a( "Microsoft Windows Me " );
            } 
            break;    case VER_PLATFORM_WIN32s:
            a( "Microsoft Win32s" );
            break;
        }
        DispMessage( ( LPCTSTR )sql );
        //delete []s;
        return; 
    }
      

  2.   

    16位程序通常是使用Windows中的GetVersion()函数是用来获取Windows及DOS版本号的,这个函数的返回值是一个四个字节的DWORD类型。低位字节返回Windows主版本号。返回值的低位字的高位字节说明Windows的副版本号,高位字的低位字节说明DOS的副版本号,高位字的高位字节说明DOS的主版本号。比如说,在Windows 95下调用这一函数返回0x07005F03。高位字0x0700说明DOS版本为7.00。低位字的低位字节0x03,低位字节0x5F(十进制95),也就是说Windows 95的Windows版本号为3.95(注意不是4.0)。下表是各版本的Windows 的GetVersion()的返回值: 
          Windows版本号 DOS版本号 
    Windows 3.x 实际的Windows版本号 实际的DOS版本号  
    Windows for Workgroup 3.11 3.10 实际的DOS版本号  
    Windows NT(16位Windows,或称WOW) 3.10 5.0  
    Windows 95 3.95 7.0 
    Windows 95 OSR2 3.95 7.1  
    GetVersion()是标准的Windows版本信息函数,但它返回的值并不总是“真实”的。例如出于兼容性的考虑,Windows for Workgroup 3.11(注意这和Windows 3.11是两个不同的版本)返回的版本号是3.10,不是3.11。你可以使用GetFileVersionInfo()函数来获得USER.EXE的版本号,它返回的将是3.11。Windows 3.2中文版返回的版本号是3.10,而不是3.20,这倒不是技术原因,而是因为Windows 3.2是在Windows 3.10的基础上汉化的。如果想知道程序是否运行在Windows NT环境下,16位程序可以调用WinFlags()函数,用返回值同WF_WINNT相与,如果不为零说明运行在Windows NT中。如果你的C++系统中没有定义WF_WINNT常数,可以加上下面这句: #define WF_WINNT 0x4000 32位程序仍可以使用GetVersion()函数,但返回值同16位不同。32位软件最好使用GetVersionEx()函数。这个函数使用OSVERSIONINFO结构,该结构是如下定义的: typedef struct _OSVERSIONINFO{ DWORD dwOSVersionInfoSize; DWORD dwMajorVersion; // 主版本号 DWORD dwMinorVersion; // 副版本号 DWORD dwBuildNumber; // Build号 DWORD dwPlatformId; TCHAR szCSDVersion[ 128 ]; } OSVERSIONINFO; 在Windows 95上,dwMajorVersion为4,dwMinorVersion为0,dwBuildNumber为950,也就是说Windows 95的版本号为4.00.950。dwPlatformId是用来区分Windows 95、Windows NT和Win32s。其取值含义如下: 
        
         
         取值 
         含义  
              VER_PLATFORM_WIN32s 
         Win32s on Windows 3.1 
              VER_PLATFORM_WIN32_WINDOWS 
         Win32 on Windows 95 
              VER_PLATFORM_WIN32_NT 
         Win32 on Windows NT 
              若想区别Windows 95与Windows 95 OSR2,要看dwBuildNumber,如果dwBuildNumber的低位字大于1080,则系统为Windows 95 OSR2或更高版本。在Win32中不再支持WinFlags()函数。 尽管GetVersionEx()函数和GetVersion ()函数是Windows提供的标准的版本函数,但在实际编程使用GetFileVersionInfo()函数有时更方便。
      

  3.   

    我这里有一个类
    'The Class get the systeminfo
    Private strMajorVer As String
    Private strMinorVer As String
    Private sngOSBuild As Single
    Private strOSPlatform As StringPrivate Declare Function GetVersionEx Lib "kernel32" _
    Alias "GetVersionExA" (lpOSInfo As OSVERINFO) As BooleanPrivate Type OSVERINFO ' Operating System Version Information
        OSVerInfoSize As Long
        MajorVer As Long
        MinorVer As Long
        BuildNo As Long
        PlatformId As Long
        strReserved As String * 128
    End TypePublic Property Get MajorVer() As String
        MajorVer = strMajorVer
    End Property
    Public Property Get MinorVer() As String
        MinorVer = strMinorVer
    End PropertyPublic Property Get OSBuild() As Single
        OSBuild = sngOSBuild
    End Property
    Public Property Get OSPlatform() As String
        OSPlatform = strOSPlatform
    End PropertyPrivate Sub Class_Initialize()' Really all the work is done here
    ' It makes all the API calls
    ' Getting version info
    Dim OSInfo As OSVERINFO
    OSInfo.OSVerInfoSize = Len(OSInfo)If GetVersionEx(OSInfo) Then
        strMajorVer = OSInfo.MajorVer
        strMinorVer = OSInfo.MinorVer
        sngOSBuild = OSInfo.BuildNo And &HFFFF&
        strOSPlatform = OSInfo.PlatformId
    End IfEnd Sub'下面是使用这个类的函数
    Private Function SystemOs() As String
    Dim SysInfo As SystemInformation
    Set SysInfo = New SystemInformation
    With SysInfo
        If .OSPlatform = 0 Then
            SystemOs = "95"
        ElseIf .OSPlatform = 1 Then
            If .MinorVer < 11 Then
                SystemOs = "98"
            Else
                SystemOs = "Me"
            End If
        ElseIf .OSPlatform = 2 Then
            If .MajorVer = 4 Then
                SystemOs = "nt"
            ElseIf .MajorVer = 5 Then
                If .MinorVer = 0 Then
                    SystemOs = "2000"
                ElseIf .MinorVer = 1 Then
                    SystemOs = "XP"
                End If
            End If
        End If
    End With
    End Function
      

  4.   

    Private Declare Function GetVersionEx Lib "kernel32" Alias "GetVersionExA" (lpVersionInformation As OSVERSIONINFO) As Long
    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 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
      

  5.   

    Private Declare Function GetVersion Lib "kernel32" () As Long
    Public Function GetWinVersion() As String
        Dim Ver As Long, WinVer As Long
        Ver = GetVersion()
        WinVer = Ver And &HFFFF&    
        GetWinVersion = Format((WinVer Mod 256) + ((WinVer \ 256) / 100), "Fixed")
    End Function
    Private Sub Form_Load()    
        MsgBox "Windows version: " + GetWinVersion
    End Sub
      

  6.   

    http://expert.csdn.net/Expert/topic/698/698837.xml?temp=9.040469E-02