Fixed: GetVersionEx deprecated under Windows 8.1+ and returns wrong version, replace it by RtlGetVersion from kernel

This commit is contained in:
kervala 2015-09-22 09:43:24 +02:00
parent 67f8fabd8b
commit 2de47a2b64

View file

@ -185,11 +185,12 @@ string CSystemInfo::getOS()
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO); typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD); typedef BOOL (WINAPI *PGPI)(DWORD, DWORD, DWORD, DWORD, PDWORD);
typedef LONG (WINAPI* pRtlGetVersion)(OSVERSIONINFOEXA*);
SYSTEM_INFO si; SYSTEM_INFO si;
PGNSI pGNSI; PGNSI pGNSI;
PGPI pGPI; PGPI pGPI;
OSVERSIONINFOEX osvi; OSVERSIONINFOEXA osvi;
BOOL bOsVersionInfoEx; BOOL bOsVersionInfoEx;
const int BUFSIZE = 80; const int BUFSIZE = 80;
@ -197,15 +198,26 @@ string CSystemInfo::getOS()
// If that fails, try using the OSVERSIONINFO structure. // If that fails, try using the OSVERSIONINFO structure.
ZeroMemory(&si, sizeof(SYSTEM_INFO)); ZeroMemory(&si, sizeof(SYSTEM_INFO));
ZeroMemory(&osvi, sizeof(OSVERSIONINFOEX)); ZeroMemory(&osvi, sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX); osvi.dwOSVersionInfoSize = sizeof(osvi);
bOsVersionInfoEx = GetVersionExA ((OSVERSIONINFO *) &osvi); HMODULE hNtDll = GetModuleHandleA("ntdll.dll");
pRtlGetVersion RtlGetVersion = (pRtlGetVersion)GetProcAddress(hNtDll, "RtlGetVersion");
if (RtlGetVersion)
{
bOsVersionInfoEx = RtlGetVersion(&osvi) == 0;
}
if(!bOsVersionInfoEx) if(!bOsVersionInfoEx)
{ {
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFO); bOsVersionInfoEx = GetVersionExA ((OSVERSIONINFOA *) &osvi);
if (! GetVersionExA ( (OSVERSIONINFO *) &osvi) ) }
if(!bOsVersionInfoEx)
{
osvi.dwOSVersionInfoSize = sizeof (OSVERSIONINFOA);
if (! GetVersionExA ( (OSVERSIONINFOA *) &osvi) )
return OSString+" Can't GetVersionEx()"; return OSString+" Can't GetVersionEx()";
} }
@ -223,13 +235,24 @@ string CSystemInfo::getOS()
{ {
OSString = "Microsoft"; OSString = "Microsoft";
if ( osvi.dwMajorVersion > 6 ) if ( osvi.dwMajorVersion > 10 )
{ {
OSString += " Windows (not released)"; OSString += " Windows (not released)";
} }
else if ( osvi.dwMajorVersion == 10 )
{
OSString += " Windows 10";
}
else if ( osvi.dwMajorVersion == 6 ) else if ( osvi.dwMajorVersion == 6 )
{ {
if ( osvi.dwMinorVersion == 2 ) if ( osvi.dwMinorVersion == 3 )
{
if( osvi.wProductType == VER_NT_WORKSTATION )
OSString += " Windows 8.1";
else
OSString += " Windows Server 2012 R2";
}
else if ( osvi.dwMinorVersion == 2 )
{ {
if( osvi.wProductType == VER_NT_WORKSTATION ) if( osvi.wProductType == VER_NT_WORKSTATION )
OSString += " Windows 8"; OSString += " Windows 8";