Need to get real OS Version

t miguel 21 Reputation points
2021-10-19T07:34:36.423+00:00

Hi need to get the real OS Version of the current machine in C++.
Essentially I need something similar to "GetVersionExW", but a version of it that:

  1. Is not deprecated
  2. Does not require the application to be explicitly manifested for the targeted OS version.
    Note: Using "GetVersionExW" or any of the "version helper functions" (https://learn.microsoft.com/en-us/windows/win32/sysinfo/version-helper-apis)
    is not acceptable, given that the application needs to be specifically manifested before they even work correctly and will not work to retrieve information about yet untargeted versions.

How can I do this? Is there already an existing function to do this? Can we have this added to Windows API?

This is extremely important to be able to remotely diagnose issues related to the target OS, and be able to remotely target specific content to those devices.
There should be no special configuration required, the only thing the application needs is to be able to run on the Windows device.

Ex usage 1. Client downloads and runs a managed software distribution application (SDA), the SDA may have only be manifested for up to Windows 10, but the SDA can get the real Windows version (ex Windows 11) be able to communicate with a repository that has a knowledge base for the current operating system and download a version of the intended software specifically optimized for a Windows 11 experience.

Ex usage 2. Client is running an application but faces usability issues related to how a custom Window appears on their desktop. They should be able to use an integrated system to be able to report the problem via the app itself, and allow us to figure out that they are running a version of Windows that we haven't tested yet.

Thanks

Windows API - Win32
Windows API - Win32
A core set of Windows application programming interfaces (APIs) for desktop and server applications. Previously known as Win32 API.
2,647 questions
C++
C++
A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.
3,754 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 85,701 Reputation points
    2021-10-19T07:54:31.903+00:00

    You can use RtlGetVersion
    But for Windows 11, it is atm identified by the Build Number (>= 22000)

                        HMODULE hDll = LoadLibrary(TEXT("Ntdll.dll"));
                        typedef NTSTATUS(CALLBACK* RTLGETVERSION) (PRTL_OSVERSIONINFOW lpVersionInformation);
                        RTLGETVERSION pRtlGetVersion;
                        pRtlGetVersion = (RTLGETVERSION)GetProcAddress(hDll, "RtlGetVersion");
                        if (pRtlGetVersion)
                        {
                            RTL_OSVERSIONINFOW ovi = { 0 };
                            ovi.dwOSVersionInfoSize = sizeof(ovi);
                            NTSTATUS ntStatus = pRtlGetVersion(&ovi);
                            if (ntStatus == 0)
                            {                           
                                WCHAR wsMessage[255] = L"";
                                wsprintf(wsMessage, L"RtlGetVersion :\r\nMajor Version : %d\r\nMinor Version : %d\r\nBuild Number : %d", ovi.dwMajorVersion, ovi.dwMinorVersion, ovi.dwBuildNumber);
                                MessageBox(NULL, wsMessage, L"Information", MB_OK | MB_ICONINFORMATION);
                            }
                        }
    
    2 people found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.