【问题标题】:C++ Windows version issue with Windows 10 home [duplicate]Windows 10 家庭版的 C++ Windows 版本问题 [重复]
【发布时间】:2016-10-12 13:05:01
【问题描述】:

我正在尝试编写一个识别当前 Windows 版本的 C++ 程序。 我看到了几十个这样的问题和答案,但没有一个对我有用。

我正在运行 Windows 10 家庭版。

我正在使用 Visual Studio 2015。

我尝试过的第一个选项:

    OSVERSIONINFO osvi;
    ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
    osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
    GetVersionEx(&osvi);
    cout << osvi.dwMajorVersion << endl;
    cout << osvi.dwMinorVersion << endl;

这将打印 6 和 2,根据 MSDN 对应于 Windows 8。

我尝试过的第二个选项:

#include <VersionHelpers.h>

if (IsWindowsVistaOrGreater())
    printf("VistaOrGreater\n");
if (IsWindows7OrGreater())
    printf("Windows7OrGreater\n");
if (IsWindows8OrGreater())
    printf("Windows8OrGreater\n");
if (IsWindows8Point1OrGreater())
    printf("Windows8Point1OrGreater\n");
if (IsWindows10OrGreater())
    printf("Windows10OrGreater\n");

这样,IsWindows10OrGreater() 没有在我的系统中定义并给出编译错误。

有什么帮助吗?

【问题讨论】:

    标签: c++ windows msdn windowsversion


    【解决方案1】:

    在 Windows 8.1 和 Windows 10 中,GetVersion 和 GetVersionEx 函数已被弃用。未针对 Windows 8.1 或 Windows 10 显示的应用程序将返回 Windows 8 操作系统版本值 (6.2)

    请参阅Targeting your application for Windows 了解更多信息。

    【讨论】:

    • 那么对于 Windows 10 来说,唯一的办法就是通过这个清单?
    • @mbaros 显然不是。链接的问题有一个非常聪明的解决方案,您可以尝试。
    • 是的。我已经看到了。谢谢
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-11-16
    • 2018-10-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多