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 that 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 that very strange?

+6
windows-7 winapi delphi
source share
3 answers

Now I have found that GetVersionEx returns Vista when my application launches through the Delphi 2009 debugger, but Windows 7 when the application runs alone. I also found that the RAD Studio (Delphi IDE) actually works in compatibility mode for Windows Vista with Service Pack 2 (SP2). Therefore, everything makes sense, since, as the kibab points out, the child process "inherits" the compatibility settings of its parent process.

+9
source share

Is your executable executable with any installed compatibility settings (suppose this can happen for legacy Delphi applications)? The GetVersionEx documentation says:

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

Maybe GetProductInfo can do what you want?

+8
source share

I think it can only be you. those. your D2009 may be marked with windows, as it should work in compatibility mode. I made a test application with your function, compiled and launched both with D2009 and D2010, inside the debugger and from the outside (click exe in Windows Explorer), and for all 4 cases it returned from: 6.1.7600 ()

Powered by Windows7, 32-bit.

+1
source share

All Articles