Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Special Interest Groups
  3. C++ Gurus
  4. Need a function to extract Windows Name & Version in C/C++
Forum Updated to NodeBB v4.3 + New Features

Need a function to extract Windows Name & Version in C/C++

Scheduled Pinned Locked Moved Unsolved C++ Gurus
3 Posts 3 Posters 2.5k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    johndummy
    wrote on last edited by johndummy
    #1

    I don't need a cross platform solution, i just need a function in C/C++ which will extract name and version of the WINDOWS OS e.g. the prototype should look like below:-

    getOSNameAndVersion(std::string &name, std::string &version);

    Name can be "Windows 7/8/8.1/10/10.1" etc
    And the same is for version.

    I don't need to cover old windows version like xp, 98 etc etc. The function should not depend on QT at all.

    J.HilkJ 1 Reply Last reply
    0
    • J johndummy

      I don't need a cross platform solution, i just need a function in C/C++ which will extract name and version of the WINDOWS OS e.g. the prototype should look like below:-

      getOSNameAndVersion(std::string &name, std::string &version);

      Name can be "Windows 7/8/8.1/10/10.1" etc
      And the same is for version.

      I don't need to cover old windows version like xp, 98 etc etc. The function should not depend on QT at all.

      J.HilkJ Offline
      J.HilkJ Offline
      J.Hilk
      Moderators
      wrote on last edited by
      #2

      @johndummy I'm kinda confused by the results I personally get, bit this should work:

      
      #include<windows.h>
      #include<stdio.h>
      int main()
      {
          OSVERSIONINFOEX info;
          ZeroMemory(&info, sizeof(OSVERSIONINFOEX));
          info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
          GetVersionEx((LPOSVERSIONINFO)&info);//info requires typecasting
      
          printf("Windows version: %u.%u\n", info.dwMajorVersion, info.dwMinorVersion);
      }
      

      Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


      Q: What's that?
      A: It's blue light.
      Q: What does it do?
      A: It turns blue.

      1 Reply Last reply
      0
      • Chris KawaC Offline
        Chris KawaC Offline
        Chris Kawa
        Lifetime Qt Champion
        wrote on last edited by Chris Kawa
        #3

        GetVersionEx is not a reliable way to get OS version. Rather what your OS tells your app what it is, and that can vary in certain compatibility conditions.

        Starting with Windows 8.1 you need a version manifest in your app. Without a manifest GetVersionEx will return 6.2 for any Windows 8 and above.
        Even if you use a manifest you get 10.0 for Windows 10 and above. To detect Windows 11 you need to look at build number. Anything above 22000 is Windows 11. There are of course a lot of different versions of 10 and 11 and things will most likely change again with 12.
        Of course in compatibility mode scenarios the OS will lie to you and give you different versions, ignoring the manifest if needed.

        That's basically why detecting OS version is generally not a good idea. Your app shouldn't care. It should care about availability of required features, and that you do by first targeting a defined minimum supported OS version by using appropriate SDK version and then dynamically loading libraries with features from above that version and checking if a query for the specific functions resolve or not.

        1 Reply Last reply
        3

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved