-1

我正在尝试编写一个识别当前 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()并给出编译错误。

有什么帮助吗?

4

1 回答 1

2

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

有关详细信息,请参阅针对 Windows 的应用程序。

于 2016-10-12T13:14:15.683 回答