Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GetVersionEx Not Working on Windows 7?

On my Windows 7 system, the GetVersionEx Windows API function returns "6.0", indicating Windows Vista, when it should return "6.1".

If it matters, I used the following Delphi code:

function winver: string;
var
  ver: TOSVersionInfo;
begin
  ver.dwOSVersionInfoSize := SizeOf(ver);
  if GetVersionEx(ver) then
    with ver do
      result := IntToStr(dwMajorVersion) + '.' + IntToStr(dwMinorVersion) + '.' + IntToStr(dwBuildNumber) + ' (' + szCSDVersion + ')';
end;

and the string "6.0.6002 (Service Pack 2)" was returned.

Isn't this highly odd?

like image 378
Andreas Rejbrand Avatar asked Apr 10 '10 12:04

Andreas Rejbrand


1 Answers

I now found that GetVersionEx returns Vista when my application runs through the Delphi 2009 debugger, but Windows 7 when the application is executed alone. I also found that RAD Studio (the Delphi IDE) actually runs in compatibility mode for Windows Vista SP2. Hence everything makes sense, for, as pointed out by kibab, a child process will "inherit" the compatibility settings of its parent process.

like image 162
Andreas Rejbrand Avatar answered Sep 28 '22 07:09

Andreas Rejbrand