2021年7月2日 星期五

取得 Windows 的版本

 在這找到好辦法 C++ How to detect Windows 10 - Stack Overflow ,保留一份

#include <iostream>
#include <windows.h>

using namespace std;

// 回報 Windows 的版本 (7, 8, 8.1, 10)
double getSysOpType()
{
    double ret = 0.0;
    NTSTATUS(WINAPI *RtlGetVersion)(LPOSVERSIONINFOEXW);
    OSVERSIONINFOEXW osInfo;

    *(FARPROC*)&RtlGetVersion = 
      GetProcAddress(GetModuleHandleA("ntdll"), "RtlGetVersion");

    if (NULL != RtlGetVersion)
    {
        osInfo.dwOSVersionInfoSize = sizeof(osInfo);
        RtlGetVersion(&osInfo);
        ret = (double)osInfo.dwMajorVersion;
    }
    return ret;
}

int main()
{
    cout << getSysOpType() << endl;
    return 0;
}





沒有留言:

張貼留言