我正在製作一個應用程序到特定的操作系統,但我似乎無法縮小Windows 10,它出現在Windows 8中。我已經在Window 10 Pro上進行了測試,結果是Major:6閔:2。是否有另一種方法來檢查它是否更有效率的Windows 10?C++檢查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();
}
一些思考:微軟曾表示,新版本的Windows將模擬舊的作爲程序清單聲稱,它是內置的版本。無論是通過兼容性庫還是虛擬機完成,未來都是開放的。但是因爲這個原因,我不確定你是否可以從應用程序中找到操作系統版本。 –
如何使用['GetVersionEx'](https://msdn.microsoft.com/en-us/library/windows/desktop/ms724451%28v=vs.85%29.aspx)?這也允許你緩存結構,你只需要調用一次。 –
**不要爲C++問題添加C標籤!** – Olaf