gpt4 book ai didi

C++ 检查是否为 Windows 10

转载 作者:可可西里 更新时间:2023-11-01 12:36:56 27 4
gpt4 key购买 nike

我正在为特定操作系统制作一个应用程序,但我似乎无法缩小 Windows 10 的范围,它以 Windows 8 的形式出现。我已经在 Window 10 Pro 上对其进行了测试,结果是 Major: 6 Min:2。有没有另一种方法可以更有效地检查它是否是 Windows 10?

编辑:找到一个正常工作的 API RtlGetVersion() 适用于所有操作系统!

#include "windows.h"
#include <iostream>
using namespace std;
BOOL EqualsMajorVersion(DWORD majorVersion)
{
OSVERSIONINFOEX osVersionInfo;
::ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFOEX));
osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
osVersionInfo.dwMajorVersion = majorVersion;
ULONGLONG maskCondition = ::VerSetConditionMask(0, VER_MAJORVERSION, VER_EQUAL);
return ::VerifyVersionInfo(&osVersionInfo, VER_MAJORVERSION, maskCondition);
}
BOOL EqualsMinorVersion(DWORD minorVersion)
{
OSVERSIONINFOEX osVersionInfo;
::ZeroMemory(&osVersionInfo, sizeof(OSVERSIONINFOEX));
osVersionInfo.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
osVersionInfo.dwMinorVersion = minorVersion;
ULONGLONG maskCondition = ::VerSetConditionMask(0, VER_MINORVERSION, VER_EQUAL);
return ::VerifyVersionInfo(&osVersionInfo, VER_MINORVERSION, maskCondition);
}
int main()
{
if (EqualsMajorVersion(7) && EqualsMinorVersion(1))
printf("Maj:7 Min:1");
else if (EqualsMajorVersion(7) && EqualsMinorVersion(0))
printf("Maj:7 Min:0");
else if (EqualsMajorVersion(6) && EqualsMinorVersion(7))
printf("Maj:6 Min:7");
else if (EqualsMajorVersion(6) && EqualsMinorVersion(6))
printf("Maj:6 Min:6");
else if (EqualsMajorVersion(6) && EqualsMinorVersion(5))
printf("Maj:6 Min:5");
else if (EqualsMajorVersion(6) && EqualsMinorVersion(4))
printf("Maj:6 Min:4");
else if (EqualsMajorVersion(6) && EqualsMinorVersion(3))
printf("Maj:6 Min:3");
else if (EqualsMajorVersion(6) && EqualsMinorVersion(2))
printf("Maj:6 Min:2");
else if (EqualsMajorVersion(6) && EqualsMinorVersion(1))
printf("Maj:6 Min:1");
else if (EqualsMajorVersion(6) && EqualsMinorVersion(0))
printf("Maj:6 Min:0");
else if (EqualsMajorVersion(5) && EqualsMinorVersion(2))
printf("Maj:5 Min:2");
else if (EqualsMajorVersion(5) && EqualsMinorVersion(1))
printf("Maj:5 Min:1");
else
printf("OS not on list...");
getchar();
}

最佳答案

这很讽刺,但是......

BOOL WINAPI IsWindows10OrGreater(void);

文档 here .

编辑:Redmond 的天才们似乎在思考原型(prototype)时遇到了问题,或者换句话说,OP 得到了评论中所述的 undefined symbol 错误。还有这个功能:

BOOL WINAPI IsWindowsVersionOrGreater(
WORD wMajorVersion,
WORD wMinorVersion,
WORD wServicePackMajor
);

而且,对于 Windows 10,wMajorVersionwMinorVersionwServicePackMajor 似乎分别是 1000

该函数的文档 here .

第二次编辑:这是官方的:IsWindowsVersionOrGreater()GetVersionEx() 从 8.1 开始被破坏。始终使用 IsWindowsXXXOrGreater(),其中 XXX 可以是 XPXPSP1XPSP2, XPSP3, Vista, VistaSP1, VistaSP2, 7, 7SP188Point110Server

关于C++ 检查是否为 Windows 10,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32193855/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com