2

I am writing code in C++ and I need to detect if I am on Windows 11. IsWindowsVersionOrGreater is an API I got that is to detects windows versions.

LINK

VERSIONHELPERAPI IsWindowsVersionOrGreater(
  WORD wMajorVersion,
  WORD wMinorVersion,
  WORD wServicePackMajor
);

What should be the argument to detect windows 11 from this API?

Need:

Windows 11 UI is different than Windows 10. Our code needs to detect windows 11 and use different UI elements and if it's below use different UI elements. We don't use windows UI elements directly but our own custom UI elements. We need to detect wins 11 and then make conscious decisions based on that. Kindly help me detect if its win 11 – Hence we need to detect.

Muzammil Ismail
  • 303
  • 4
  • 9
MAG
  • 2,841
  • 6
  • 27
  • 47
  • 1
    Do you actually need to detect Windows 11 rather than availability of a specific API or feature? – IInspectable Oct 18 '21 at 06:48
  • Yes @IInspectable , we need to detect if it's win 11 . Edited the question to include this information – MAG Oct 18 '21 at 07:52
  • 1
    @MAG: Sounds like you want to detect the availability of those different UI elements, not Windows 11. It's pretty safe to predict that like Windows 10, there will be many similar-but-not-identical versions of Windows 11. And on the flip side, Windows Server is not Windows 11 but may still have those UI elements. – MSalters Oct 18 '21 at 08:06
  • We don't use windows UI elements directly but our own custom UI elements . – MAG Oct 18 '21 at 08:37
  • we need to detect win 11 and then make concious decisions based on that . Kindly help me detect its win 11 – MAG Oct 18 '21 at 08:38
  • use `RtlGetNtVersionNumbers` and if version >= *10.0.22000* this is win11 or higer – RbMm Oct 18 '21 at 09:49
  • RtlGetNtVersionNumbers api gave wrong build version DWORD majorVersion = 0, minorVersion = 0, buildVersion = 0; typedef void (WINAPI* getver)(DWORD*, DWORD*, DWORD*); getver gv; gv = (getver)GetProcAddress(hm, "RtlGetNtVersionNumbers"); if (gv) { gv(&majorVersion, &minorVersion, &buildVersion); – MAG Oct 18 '21 at 10:30
  • 1
    no, it always get correct. simply high 4 bits have - 'C' or 'F' in high nibble to indicate free/checked. look for this - https://pastebin.com/AuprPaEm and you not need use `GetProcAddress` - simply link with *ntdll.lib* – RbMm Oct 18 '21 at 11:10
  • I know for Windows 10, some of those version detection functions require that the EXE that is running has a manifest indicating that it supports Windows 10. I assume it would be the same for Windows 11. Be sure the manifest has the requisite entries otherwise the version you detect might be Windows 7 or lower. – Joseph Willcoxson Oct 18 '21 at 14:16
  • @JosephWillcoxson - depend from api. `RtlGetNtVersionNumbers` not require any manifest and always return real windows version – RbMm Oct 18 '21 at 14:41
  • i searched more . Interestingly we need to do buildVersion &= 0xffff; to get the correct version . After this the version is correct . – MAG Oct 18 '21 at 15:17
  • @MAG also see [`RtlGetVersion()`](https://learn.microsoft.com/en-us/windows-hardware/drivers/ddi/wdm/nf-wdm-rtlgetversion) – Remy Lebeau Oct 18 '21 at 16:18
  • @JosephWillcoxson except that there is no `supportedOS` guid defined for Windows 11, just continue using the Windows 10 guid: https://stackoverflow.com/questions/68240304/ – Remy Lebeau Oct 18 '21 at 16:19
  • *Interestingly we need to do buildVersion &= 0xffff; to get the correct version* - more exactly `buildVersion &= 0x0fffffff` – RbMm Oct 18 '21 at 20:16
  • without GetProcAddress you wont be able tocall the function . What are you suggesting above @RbMm .. sorry missed that point about simply linking with ntdll will work – MAG Oct 19 '21 at 12:50
  • `RtlGetNtVersionNumbers` is exported by ntdll how minimum from xp and i sure that it will be exported alwaus, in any new windows version. as result we can use static linking. – RbMm Oct 19 '21 at 12:52
  • why don't just use the standard UI frameworks from MS? That way the UI will automatically show properly on each OS – phuclv Mar 19 '22 at 10:10
  • Does this answer your question? [Detect Windows 11 with .NET Framework or Windows API](https://stackoverflow.com/questions/69038560/detect-windows-11-with-net-framework-or-windows-api) – phuclv Mar 19 '22 at 10:10

0 Answers0