[C++] Detect Windows Build?

ravi jagannadhan 1 Reputation point
2021-12-22T21:33:00.287+00:00

I have some code that depends on APIs that have changed from Windows 10 Build 20348 onwards. Is there a reliable way to check which build my app is running on?

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,618 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,527 questions
Windows 11
Windows 11
A Microsoft operating system designed for productivity, creativity, and ease of use.
8,166 questions
{count} votes

3 answers

Sort by: Most helpful
  1. Minxin Yu 10,031 Reputation points Microsoft Vendor
    2021-12-23T02:58:00.013+00:00

    Hi, @ravi jagannadhan
    The RtlGetVersion routine returns version information about the currently running operating system. You could try the snippet below.

     #include <iostream>  
     #include<Windows.h>  
      
    typedef LONG NTSTATUS, * PNTSTATUS;  
    #define STATUS_SUCCESS (0x00000000)  
      
    typedef NTSTATUS(WINAPI* RtlGetVersionPtr)(PRTL_OSVERSIONINFOW);  
      
    RTL_OSVERSIONINFOW GetRealOSVersion() {  
        HMODULE hMod = ::GetModuleHandleW(L"ntdll.dll");  
        if (hMod) {  
            RtlGetVersionPtr fxPtr = (RtlGetVersionPtr)::GetProcAddress(hMod, "RtlGetVersion");  
            if (fxPtr != nullptr) {  
                RTL_OSVERSIONINFOW rovi = { 0 };  
                rovi.dwOSVersionInfoSize = sizeof(rovi);  
                if (STATUS_SUCCESS == fxPtr(&rovi)) {  
                    return rovi;  
                }  
            }  
        }  
        RTL_OSVERSIONINFOW rovi = { 0 };  
        return rovi;  
    }  
    int main()  
    {  
        auto VN=GetRealOSVersion();  
        std::cout << VN.dwBuildNumber ;  
          
    }  
    

    159855-%E5%B1%8F%E5%B9%95%E6%88%AA%E5%9B%BE-2021-12-23-103636.jpg

    Windows 10 build 18362 (also known as SDK version 1903)

    The number in the picture is the build I got.

    Best regards,

    Minxin Yu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Castorix31 81,726 Reputation points
    2021-12-23T04:44:29.82+00:00

    See this recent thread : Need to get real OS Version

    0 comments No comments

  3. Limitless Technology 39,356 Reputation points
    2021-12-27T18:31:18.46+00:00

    GetVersion, GetVersionEx, VerifyVersionInfo, and the Version Helper functions are for desktop apps only. Universal Windows apps can use the AnalyticsInfo.VersionInfo property for telemetry and diagnostic logs.

    In order for your app to target Windows 8.1 or later, you'll need to include an app (executable) manifest for the app's executable.

    Targeting your application for Windows
    https://learn.microsoft.com/en-us/windows/win32/sysinfo/targeting-your-application-at-windows-8-1

    Hope this resolves your Query!!

    -------

    --If the reply is helpful, please Upvote and Accept it as an answer--

    0 comments No comments