Skip to content

Instantly share code, notes, and snippets.

@jay
Last active March 22, 2024 22:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jay/ae07fba61fe6853f5620eb142c66807b to your computer and use it in GitHub Desktop.
Save jay/ae07fba61fe6853f5620eb142c66807b to your computer and use it in GitHub Desktop.
test of GetVersionExW, RtlGetVersion and RtlGetNtVersionNumbers on Windows 11.
/*
test of GetVersionExW, RtlGetVersion and RtlGetNtVersionNumbers on Windows 11.
can be built with cygwin/mingw/mingw-w64 gcc or microsoft cl.
https://cygwin.com/pipermail/cygwin/2024-March/255728.html
---
without manifest:
>test-RtlGetNtVersionNumbers.exe
GetVersionExW: 6.2.9200
RtlGetVersion: 10.0.22000
RtlGetNtVersionNumbers: 10 major, 0 minor, 4026553840 unknown
LOWORD of unknown: 22000 (0x55f0)
HIWORD of unknown: 61440 (0xf000)
with manifest:
mt.exe -nologo -manifest test-RtlGetNtVersionNumbers.exe.manifest -outputresource:test-RtlGetNtVersionNumbers.exe;#1
>test-RtlGetNtVersionNumbers.exe
GetVersionExW: 10.0.22000
RtlGetVersion: 10.0.22000
RtlGetNtVersionNumbers: 10 major, 0 minor, 4026553840 unknown
LOWORD of unknown: 22000 (0x55f0)
HIWORD of unknown: 61440 (0xf000)
---
Public Domain: No License. Written by Jay Satiro <raysatiro@yahoo.com>
https://gist.github.com/jay/ae07fba61fe6853f5620eb142c66807b
*/
#define WIN32_NO_STATUS
#include <windows.h>
#undef WIN32_NO_STATUS
#ifdef __MINGW32__
#include <_mingw.h>
#ifdef __MINGW64_VERSION_MAJOR
#include <ntstatus.h>
#else
#include <ddk/ntddk.h>
#endif
#else
#include <ntstatus.h>
#endif
#include <stdio.h>
OSVERSIONINFOW os = { sizeof os, };
RTL_OSVERSIONINFOW rtl_os = { sizeof rtl_os, };
int main()
{
NTSTATUS (NTAPI *RtlGetVersion)
(RTL_OSVERSIONINFOW *lpVersionInformation) =
(NTSTATUS (NTAPI *)(RTL_OSVERSIONINFOW *))
GetProcAddress(GetModuleHandleW(L"ntdll"), "RtlGetVersion");
VOID (NTAPI *RtlGetNtVersionNumbers)
(DWORD *major, DWORD *minor, DWORD *unknown) =
(VOID (NTAPI *)(DWORD *, DWORD *, DWORD *))
GetProcAddress(GetModuleHandleW(L"ntdll"), "RtlGetNtVersionNumbers");
if(GetVersionExW(&os)) {
printf("GetVersionExW: %u.%u.%u\n",
os.dwMajorVersion, os.dwMinorVersion, os.dwBuildNumber);
}
else
printf("GetVersionExW failed, error %u\n", GetLastError());
if(RtlGetVersion) {
NTSTATUS ntstatus = RtlGetVersion(&rtl_os);
if(ntstatus >= 0) {
printf("RtlGetVersion: %u.%u.%u\n",
rtl_os.dwMajorVersion, rtl_os.dwMinorVersion, rtl_os.dwBuildNumber);
}
else
printf("RtlGetVersion failed, error 0x%08x\n", ntstatus);
}
else
printf("RtlGetVersion not found in ntdll\n");
if(RtlGetNtVersionNumbers) {
DWORD major = 0, minor = 0, unknown = 0;
RtlGetNtVersionNumbers(&major, &minor, &unknown);
printf("RtlGetNtVersionNumbers: %u major, %u minor, %u unknown\n"
"LOWORD of unknown: %u (0x%04x)\n"
"HIWORD of unknown: %u (0x%04x)\n",
major, minor, unknown,
LOWORD(unknown), LOWORD(unknown),
HIWORD(unknown), HIWORD(unknown));
}
else
printf("RtlGetNtVersionNumbers not found in ntdll\n");
return 0;
}
<?xml version="1.0" encoding="utf-8"?>
<assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1">
<assemblyIdentity version="1.0.0.0" name="VersionOfWindows.app"/>
<!--
This manifest entries are important for getting the Windows version correctly
while using the Version Helper header
-->
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
<!-- A list of the Windows versions that this application has been tested on
and is designed to work with. Uncomment the appropriate elements
and Windows will automatically select the most compatible environment. -->
<!-- Windows Vista -->
<supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}" />
<!-- Windows 7 -->
<supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}" />
<!-- Windows 8 -->
<supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}" />
<!-- Windows 8.1 -->
<supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}" />
<!-- Windows 10 -->
<supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}" />
</application>
</compatibility>
</assembly>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment