6

I wrote a piece of code to retrieve windows major and minor version using GetVersionEx function, but this function always returns major version 6 and minor version 2.

MSDN is saying to use Version Helper APIs to find the current OS. I built the project in windows 8.1 and referred Windows 8.1 kits path to include VersionHelpers header file. There is no IsWindows10OrGreater() function available in VersionHelpers header file.

So I downloaded VersionHelper header file from GitHub and added into my project. Compile error gone but IsWindows10OrGreater function is getting fail.

Am i doing anything wrong?

Jabberwocky
  • 48,281
  • 17
  • 65
  • 115
user2385610
  • 61
  • 1
  • 4
  • 1
    Where did you download your VersionHelper.h from? GitHub doesn't only host one project... – Simon Kraemer Nov 06 '15 at 12:41
  • 5
    If you want GetVersionEx to return the correct version, you should specify window 8.1/10 support in your manifest https://msdn.microsoft.com/en-us/library/windows/desktop/dn481241%28v=vs.85%29.aspx – zenden2k Nov 06 '15 at 12:43
  • 1
    Microsoft has promised for a long time that they'll defeat version checks. That is executed in full in Win10. The only way to get version 10 back is to build your program to target Win10. Project > Properties > Linker > System > Minimum Required Version must be set to "10.0". That this is entirely pointless is not an accident :) The only other way to do it is to obtain the version resource from a DLL like kernel32.dll – Hans Passant Nov 06 '15 at 13:06
  • To follow up on @Hans Passant's comment, Raymond Chen's [article](http://blogs.msdn.com/b/oldnewthing/archive/2004/02/13/72476.aspx) about why Windows 95 called itself version 3.95 instead of 4.0 has some background about why version number reporting is weird in Windows. TL;DR; - People write version checks wrong, so the API just reports a 'wrong' version number so that the new OS can run old software. – theB Nov 06 '15 at 13:25
  • @HansPassant is that the linker setting for the subsystem version? and if so, what's the difference between this and the manifest? – andlabs Nov 06 '15 at 15:01
  • 1
    The manifest does not declare a subsystem version. It could have the `` element but that only worked in the preview version of Win10, it was removed again for RTM. – Hans Passant Nov 06 '15 at 16:00
  • Thank you for your quick reply.I download full project from Github.I took VersionHelper.h file from the project and added into my project.Can you please tell me how to add manifest file into my project? – user2385610 Nov 11 '15 at 09:55
  • Related: [C++ How to detect Windows 10](https://stackoverflow.com/q/32115255/3357935) – Stevoisiak Mar 13 '19 at 18:07

1 Answers1

14

The VersionHelper functions are simply wrappers for VerifyVersionInfo(). Starting in Windows 10, VerifyVersionInfo() is now subject to the same version manifestation rules that GetVersionEx() is subject to. To get the true OS version regardless of manifestation, you can use RtlGetVersion(), NetServerGetInfo(), or NetWkstaGetInfo() instead.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770