开发者

GetVersionEx Not Working on Windows 7?

开发者 https://www.devze.com 2022-12-26 14:58 出处:网络
On my Windows 7 system, the GetVersionEx Windows API function returns \"6.0\", indicating Windows Vista, when it should return \"6.1\".

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.dwOSVersionIn开发者_运维技巧foSize := 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?


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.


Is your executable running with any compatibility settings defined (I assume this might be the case for legacy Delphi applications)? The documentation of GetVersionEx states:

If compatibility mode is in effect, the GetVersionEx function reports the operating system as it identifies itself, which may not be the operating system that is installed. For example, if compatibility mode is in effect, GetVersionEx reports the operating system that is selected for application compatibility.

Maybe GetProductInfo can do what you want?


I think it may just be you. i.e. your D2009 may have been marked by windows, as needing to run in compatibility mode. I made a test app with your function, and compiled and ran both with D2009 and D2010, inside the debugger and externally (click the exe in windows explorer), and for all 4 cases, it came back with: 6.1.7600 ()

Running on Windows7, 32-bit.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号