Jackzz Jackzz - 1 year ago 129
C++ Question

Get OSVersion in Windows using C++

I have to get the

of my
System (version should be
NT 6.2
) to use in a C++ application. I tried using
function call. but it returned me a raw value like
. Is there some way by which I can get the versions as listed here or how can I convert this raw value to a readable form?

Answer Source

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

Possible usage:

void print_os_info()
    ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
    info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);


    printf("Windows version: %u.%u\n", info.dwMajorVersion, info.dwMinorVersion);

I don't understand, what do you mean by NT. According to MSDN:

Version table

Since Windows XP, all versions are implicitly NT versions. If you want to test against Server versions, check value of info.wProductType:

if(info.dwMajorVersion == 6)
    if (info.dwMinorVersion == 0)
        if (info.wProductType == VER_NT_WORKSTATION)
            //Windows Vista;
            //Windows Server 2008
    else if (info.dwMinorVersion == 1)
        if (info.wProductType == VER_NT_WORKSTATION)
            //Windows 7
            //Windows Server 2008 R2
    else if (...) //etc...

And one more thing: you can also check value of info.dwBuildNumber. One of allowed values is VER_PLATFORM_WIN32_NT.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download