獲得當前Windows作業系統版本的詳細描述資訊

來源:互聯網
上載者:User
獲得當前Windows作業系統版本的詳細描述資訊。
目前支援的版本到Windows 2003。

CString GetOSDesc(void)
{
    CString sOSInfo, sTmp;
    OSVERSIONINFOEX osvi;
    BOOL bOsVersionInfoEx;

    sOSInfo = "N/A";

    // Try calling GetVersionEx using the OSVERSIONINFOEX structure.
    // If that fails, try using the OSVERSIONINFO structure.
    ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);

    if (!(bOsVersionInfoEx = GetVersionEx((OSVERSIONINFO *) &osvi)))
    {
        osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
        if (!GetVersionEx((OSVERSIONINFO*)&osvi))
            return sOSInfo;
    }

    switch (osvi.dwPlatformId)
    {
    // Test for the Windows NT product family.
    case VER_PLATFORM_WIN32_NT:
        // Test for the specific product family.
        if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
            sOSInfo = "Microsoft Windows Server 2003 family ";

        if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 1)
            sOSInfo = "Microsoft Windows XP ";

        if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
            sOSInfo = "Microsoft Windows 2000 ";

        if (osvi.dwMajorVersion <= 4)
            sOSInfo = "Microsoft Windows NT ";

        // Test for specific product on Windows NT 4.0 SP6 and later.
        if (bOsVersionInfoEx)
        {
            // Test for the workstation type.
            if (osvi.wProductType == VER_NT_WORKSTATION)
            {
                if(osvi.dwMajorVersion == 4)
                    sOSInfo += "Workstation 4.0 " ;
                else if( osvi.wSuiteMask & VER_SUITE_PERSONAL )
                    sOSInfo += "Home Edition ";
                else
                    sOSInfo += "Professional ";
            }
            // Test for the server type.
            else if (osvi.wProductType == VER_NT_SERVER)
            {
                if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 2)
                {
                    if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
                        sOSInfo += "Datacenter Edition ";
                    else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
                        sOSInfo += "Enterprise Edition ";
                    else if (osvi.wSuiteMask == VER_SUITE_BLADE)
                        sOSInfo += "Web Edition ";
                    else
                        sOSInfo += "Standard Edition ";
                }
                else if (osvi.dwMajorVersion == 5 && osvi.dwMinorVersion == 0)
                {
                    if (osvi.wSuiteMask & VER_SUITE_DATACENTER)
                        sOSInfo += "Datacenter Server ";
                    else if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
                        sOSInfo += "Advanced Server ";
                    else
                        sOSInfo += "Server ";
                }
                else  // Windows NT 4.0
                {
                    if (osvi.wSuiteMask & VER_SUITE_ENTERPRISE)
                        sOSInfo += "Server 4.0, Enterprise Edition ";
                    else
                        sOSInfo += "Server 4.0 ";
                }
            }
        }
        else  // Test for specific product on Windows NT 4.0 SP5 and earlier
        {
            HKEY hKey;
            char szProductType[80];
            DWORD dwBufLen=80;
            LONG lRet;

            sTmp = "SYSTEM//CurrentControlSet//Control//ProductOptions";
            lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sTmp,
                0, KEY_QUERY_VALUE, &hKey);
            if( lRet != ERROR_SUCCESS )
                return sOSInfo;

            sTmp = "ProductType";
            lRet = RegQueryValueEx(hKey, sTmp, NULL, NULL, (LPBYTE)szProductType, &dwBufLen);
            if( (lRet != ERROR_SUCCESS) || (dwBufLen > 80) )
                return sOSInfo;

            RegCloseKey( hKey );

            sTmp = "WINNT";
                sOSInfo += "Workstation ";
            sTmp = "LANMANNT";
            if (sTmp == szProductType)
                sOSInfo += "Server ";
            sTmp = "SERVERNT";
            if (sTmp == szProductType)
                sOSInfo += "Advanced Server ";

            sTmp.Format(L"%d.%d ", osvi.dwMajorVersion, osvi.dwMinorVersion);
            sOSInfo += sTmp;
        }

        // Display service pack (if any) and build number.
        sTmp = "Service Pack 6";
        if (osvi.dwMajorVersion == 4 && (sTmp == osvi.szCSDVersion))
        {
            HKEY hKey;
            LONG lRet;

            // Test for SP6 versus SP6a.
            sTmp = "SOFTWARE//Microsoft//Windows NT//CurrentVersion//Hotfix//Q246009";
            lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, sTmp,
                0, KEY_QUERY_VALUE, &hKey);
            if( lRet == ERROR_SUCCESS )
            {
                sTmp.Format(L"Service Pack 6a (Build %d)/n", osvi.dwBuildNumber & 0xFFFF);
                sOSInfo += sTmp;
            }
            else // Windows NT 4.0 prior to SP6a
            {
                sTmp.Format(L"%s (Build %d)/n", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
                sOSInfo += sTmp;
            }

            RegCloseKey( hKey );
        }
        else // Windows NT 3.51 and earlier or Windows 2000 and later
        {
            sTmp.Format(L"%s (Build %d)/n", osvi.szCSDVersion, osvi.dwBuildNumber & 0xFFFF);
            sOSInfo += sTmp;
        }
        break;

    // Test for the Windows 95 product family.
    case VER_PLATFORM_WIN32_WINDOWS:
        if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 0)
        {
            sOSInfo = "Microsoft Windows 95 ";
            if (osvi.szCSDVersion[1] == 'C' || osvi.szCSDVersion[1] == 'B')
                sOSInfo += "OSR2 ";
        }

        if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 10)
        {
            sOSInfo = "Microsoft Windows 98 ";
            if (osvi.szCSDVersion[1] == 'A')
                sOSInfo += "SE ";
        }

        if (osvi.dwMajorVersion == 4 && osvi.dwMinorVersion == 90)
        {
            sOSInfo = "Microsoft Windows Millennium Edition";
        }
        break;

    case VER_PLATFORM_WIN32s:
        sOSInfo = "Microsoft Win32s";
        break;
    }

    return sOSInfo;
}

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.