GetVersionEx() depreciated, what should be used instead for Windows 7/8/10?
Christian Franke
Christian.Franke@t-online.de
Wed Mar 20 11:39:46 GMT 2024
Corinna Vinschen via Cygwin wrote:
> On Mar 19 09:18, Bill Stewart via Cygwin wrote:
>> On Tue, Mar 19, 2024 at 9:01 AM Richard Campbell wrote:
>>
>> On Tue, Mar 19, 2024 at 9:04 AM Bill Stewart via Cygwin <cygwin@cygwin.com>
>>> wrote:
>>>
>>>> Can you please clarify the circumstances under which the RtlGetVersion
>>>> function "may not return the correct values"?
>>> "Originally, using RtlGetVersion instead of GetVersionEx was supposed to
>>> fix the fact that GetVersionInfo returns the wrong kernel version if the
>>> executable has been built with an old manifest (or none at all), starting
>>> with Windows 8.1. Either this never really worked as desired and our
>>> testing was flawed, or this has been changed again with Windows 10, so
>>> that RtlGetVersion does the kernel faking twist as well. Since we're
>>> only reading the value in the first process in a process tree. the entire
>>> process tree is running with a wrong OS version information in that case.
>>>
>>> Fortunately, the (undocumented) RtlGetNtVersionNumbers function is not
>>> affected by this nonsense, so we simply override the OS version info
>>> fields with the correct values now."
>>>
>>> https://cygwin.com/git/?p=newlib-cygwin.git;a=commitdiff;h=48511f3d3847c35352d09cded56e25f0c1b22bc9
>>>
>> Interesting. I have not yet been able to find a scenario where the
>> RtlGetVersion function gets "manifested" like GetVersionEx.
>>
>> I wrote a small Win32 console utility for displaying and testing OS
>> information (requires Windows Vista/Server 2008 or later):
>>
>> https://github.com/Bill-Stewart/osinfo
>>
>> It uses RtlGetVersion, and this function works correctly for me in all
>> current Windows versions (Windows 10, Server 2016, Windows 11, Server 2019,
>> Server 2022, etc.).
>>
>> I'm not sure of the exact scenario that led to the "RtlGetVersion is
>> subject to manifesting" conclusion, but I can't reproduce it.
> You have to create an application with an application manifest not
> supporting your OS.
>
> For Cygwin apps, this occured when you built, say, an executable under
> Windows 8.1 before Windows 10 support was added to the Cygwin toolchain:
> the manifest linked to the Cygwin executable didn't yet contain a GUID
> entry for Windows 10 support.
>
> In this case, RtlGetVersion returns an OS version 6.3 even when running
> under the 10.0 kernel. This behaviour exists back 'til Windows Vista.
Could not reproduce the latter on Win10. I tested with recent Win10 and
Win11 and also found a Win10 1511 (and Slackware 1.1.2, Win3.1, OS/2,
...) in my VM image museum.
Regardless of the exe manifest, RtlGetVersion and RtlGetNtVersionNumbers
return the correct versions:
10.0.22621 (Win11 22H2)
10.0.19045 (Win10 22H2)
10.0.10586 (Win10 1511)
Without a manifest, GetVersionEx returns:
6.2.9200 (Win8)
--
Regards,
Christian
More information about the Cygwin
mailing list