/ src / common / sysinternals / WindowsVersions.cpp
WindowsVersions.cpp
 1  #include <Windows.h>
 2  
 3  #include "WindowsVersions.h"
 4  
 5  // Declared in wdm.h
 6  typedef NTSYSAPI NTSTATUS (NTAPI *RtlGetVersionType)( PRTL_OSVERSIONINFOW );
 7  
 8  DWORD GetWindowsBuild( DWORD* revision )
 9  {
10      if( revision ) {
11  
12          DWORD size = sizeof( *revision );
13          if( RegGetValueW( HKEY_LOCAL_MACHINE, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", L"UBR", RRF_RT_REG_DWORD, NULL, revision, &size ) != ERROR_SUCCESS ) {
14  
15              *revision = 0;
16          }
17      }
18  
19      RtlGetVersionType pRtlGetVersion = reinterpret_cast<RtlGetVersionType>(GetProcAddress( GetModuleHandleW( L"ntdll.dll" ), "RtlGetVersion" ));
20      
21      RTL_OSVERSIONINFOW version;
22      pRtlGetVersion( &version );
23      return version.dwBuildNumber;
24  }