5

I am using this code to detect the WindowsVersion on a PC.

function GetOS: string;
var
 osVerInfo: TOSVersionInfo;
 majorVer, minorVer: Integer; 
begin
Result := 'Unknown';
osVerInfo.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
if GetVersionEx(osVerInfo) then
 begin
  majorVer := osVerInfo.dwMajorVersion;
  minorVer := osVerInfo.dwMinorVersion;
  case osVerInfo.dwPlatformId of
  VER_PLATFORM_WIN32_NT: {Mirosoft Windows NT/2000 }
    begin
      if majorVer <= 4 then
        Result := 'Win NT'
      else if (majorVer = 5) and (minorVer = 0) then
        Result := 'Win 2k'
      else if (majorVer = 5) and (minorVer = 1) then
        Result := 'Win XP'
      else if (majorVer = 6) and (minorVer = 0) then
        Result := 'Win Vista'
      else if (majorVer = 6) and (minorVer = 1) then
        Result := 'Win 7'
      else if (majorVer = 6) and (minorVer = 2) then
        Result := 'Win 8'
    end;
  VER_PLATFORM_WIN32_WINDOWS:  { Windows 9x/ME }
    begin
      if (majorVer = 4) and (minorVer = 0) then
        Result := 'Win 95'
      else if (majorVer = 4) and (minorVer = 10) then
      begin
        if osVerInfo.szCSDVersion[1] = 'A' then
          Result := 'Win 98SE'
        else
          Result := 'Win 98';
      end
      else if (majorVer = 4) and (minorVer = 90) then
        Result := 'Win ME'
    end;
  end;
end;
end;

For some reason it says that Windows8 Consumer Preview Build 8250 (32bit) is Windows XP - Major Version 5. I checked and it's supposed to be Version 6.2 (according to notepad.exe on windows8) Is this a bug or is something wrong? btw. my Windows 8 is up2date.

Any Ideas?

EDIT: ScreenShot GETOS

Ben
  • 3,380
  • 2
  • 44
  • 98
  • 4
    Have you tried debugging it? Check to see what you get back in `osVerInfo` and trace through it to see how you end up with that result. That'll give you an idea of what's going on. – Mason Wheeler May 11 '12 at 19:16
  • I looked through the entire osVerInfo and debugged it. It says Major Version 5. – Ben May 11 '12 at 19:19
  • 7
    maybe your app is running under XP compatibility mode ? – Antonio Bakula May 11 '12 at 19:25
  • 1
    The [GetVersionEx function works fine](http://stackoverflow.com/questions/9817160/getversionex-under-windows-8) under Windows 8, I just tested a Delphi XE2 application under Windows 8 Developer Preview and the `GetVersionEx` returns 6.2, so has @AntonioBakula says probably your are executing you app in XP compatibility mode. – RRUZ May 11 '12 at 19:33
  • 1
    That was it. The Delphi7 IDE runs under compatibility mode. I totally forgot about that. Thank you very much. – Ben May 11 '12 at 19:34
  • 2
    Then would be fair if @Antonio post that as the answer and you would accept it ;-) – TLama May 11 '12 at 19:37
  • 2
    posted as answer, I wasn't sure that this was a reason so I posted comment :) – Antonio Bakula May 11 '12 at 19:41
  • 1
    FWIW The Delphi IDE, even for D7, does not need compat mode. – David Heffernan May 11 '12 at 20:09

2 Answers2

11

The reason for this behavior is XP Compatibility mode, Delphi 7 IDE was running under compatibility mode.

Antonio Bakula
  • 20,445
  • 6
  • 75
  • 102
1

For Windows 8.0 the version 6.2 is correct - also the Build-Number. With Windows 8.1 you get version 6.2 too. But now the Version-Number ist 6.3 Build 9600. You can see it in the system-info. GetVersionEx allows only 0,1,2 for Win32MinorVersion. If you need this info, you can read it from registry-key 'Version' in HKCU\Software\Microsoft\Internet Explorer\Main\WindowsSearch. Best regards, asks

Asks
  • 11
  • 1