Search code examples
c++windowsc++17version

Check if windows10 is installed C++


I must check if windows 10 is installed on machine, because my program supports only win10.

I tried this solution that I already found on stackoverflow.

    if (IsWindowsVersionOrGreater(10, 0, 0))
    {
        //nothing
    }
    else
    {
        MessageBox(NULL, "Your OS is not supported.", "Version Not Supported", MB_OK);
    }

It giving me Your OS is not supported but why? Did I understand something wrong? Is there any other solutions to do it?

Best regards.


Solution

  • Have you looked at GetVersionEx() function and OSVERSIONINFOEX structure?

    Possible usage:

    void print_os_info()
    {
        OSVERSIONINFOEX info;
        ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
        info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
    
        GetVersionEx(&info);
    
        printf("Windows version: %u.%u\n", info.dwMajorVersion, info.dwMinorVersion);
    }
    

    this is the source of the answer: Get OSVersion in Windows using C++