This question already has answers here:
C++ How to detect Windows 10

(5个答案)


去年关闭。




我正在使用GetVersionEx来获取操作系统。但是我不知道为什么将Windows 10报告为Windows 8?我知道它已被弃用,但找不到其他解决方案。

switch (osinfo.dwMajorVersion)
    {
    case 5:
        if (osinfo.dwMinorVersion == 0)
        {
            sysinfo = "Windows 2000 ";
        }
        else if (osinfo.dwMinorVersion == 1)
        {
            sysinfo = "Windows XP ";
        }
        else if (osinfo.dwMinorVersion == 2)
        {
            sysinfo = "Windows XP ";
        }
        break;
    case 6:
        if (osinfo.dwMinorVersion == 3)
        {
            sysinfo = "Windows 8.1 ";
        }
        else if (osinfo.dwMinorVersion == 2)
        {
            sysinfo = "Windows 8 ";
        }
        else if (osinfo.dwMinorVersion == 1)
        {
            sysinfo = "Windows 7 ";
        }
        else {
            sysinfo = "Windows Vista ";
        }
        break;
    case 10:
        sysinfo = "Windows 10 ";
        break;
    default:
        sysinfo = "Unknown OS ";
    }

最佳答案

documentation:



这里有很多细节,但是有些困难。在底部,它提出了一个概念,即获取操作系统版本不是一件好事:



该链接建议使用 BOOL IsOS(DWORD dwOS) 函数,该参数是大约40个选项之一,例如OS_WIN95ORGREATER,OS_WIN2000TERMINAL,OS_PROFESSIONAL等。

或者,还有 GetProductInfo() 似乎具有更详细的结果。

08-17 04:55