Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Discover & Report Windows Version Info from C program [duplicate]

Tags:

c

windows

winapi

We had a project built for Win2K, then WinXP, then Win7 that has now been converted from a 32-bit Win7 program using VS2010 to a 64-bit Win10 program using VS2017. The VS2017 project was created from scratch and the old sources where then imported and updated as needed.

When I created the new project, I set the Target Platform (in the project's Configuration, General section) to Windows 10 and since I have no special needs, I set the project to build a manifest automatically.

Today I noticed that the dialog we have that shows the current Windows version info in the program says they we are running under Windows 8.1, internal version number 6.2. When I looked up the GetVersionInfo function I found out that it "lies" for programs that do not have a manifest saying they target Windows 10.

My question is in two parts:

  1. Since I used the VS2017 to target Windows 10 and build the manifest automatically, why is the function that only lies to programs that are NOT targeted to Windows 10 lying to my program? Shouldn't it have built the manifest correctly if it is going to do it at all?
  2. If VS2017 cannot or will not correctly target my program for Windows 10, can anyone help me find an example of how to manually do that with a plain C project? (Microsoft is not helpful with comments like "just add the necessary SXS symbols to your .rc file" -- I'm not going to randomly stick code in the .rc file by hand, hoping I accidentally stick it is the right place!)

I freely admit my ignorance of the manifest stuff. To date, I have not knowingly run into any situation where I needed to know about it.

[EDIT] Just a minor comment for the "this is a duplicate" crowd. My program doesn't CARE what version of Windows it finds, but it needs to REPORT as much detail about that version as possible. We display the information in one of our dialogs (and write it to a file) that we use when supporting customers. This allows us to ensure we build a test system with the exact same Windows as the customer. The primary focus of the "duplicates" is to ensure a program is running on the correct version of Windows, while mine is reporting all of the Windows version info I can find, so to me, this is NOT actually a duplicate of the others, although the RtlGetVersion() function (thanks @RemyLebeau) appears to solve both types of problem.

like image 720
Steve Valliere Avatar asked Mar 10 '26 00:03

Steve Valliere


1 Answers

Proceed like this:

First create a manifest file in your project folder and call it for example manifest.xml, then add it to your project in the Solution Explorer:

enter image description here

It should have this content:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="asInvoker" uiAccess="false"></requestedExecutionLevel>
      </requestedPrivileges>
    </security>
  </trustInfo>
  <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"></supportedOS>
      <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"></supportedOS>
      <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"></supportedOS>
      <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"></supportedOS>
      <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"></supportedOS>
    </application>
  </compatibility>
</assembly>

Then right click on your project in the Solution Explorer. And modify the as shown below:

enter image description here

like image 78
Jabberwocky Avatar answered Mar 12 '26 17:03

Jabberwocky



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!