Einzelnen Beitrag anzeigen

Benutzerbild von Nersgatt
Nersgatt

Registriert seit: 12. Sep 2008
Ort: Emlichheim
693 Beiträge
 
Delphi 10.1 Berlin Professional
 
#1

Falscher Product Type in OSVersionInfoEx

  Alt 7. Dez 2012, 09:47
Moin,

ich ermittle wie folgt die Windowsversion
Delphi-Quellcode:
function GetOSVersionInfoEx : TOSVersionInfoEx;
var
  OSVersionInfo : TOSVersionInfo absolute Result;
  Done : Boolean;
begin
  FillChar(Result, SizeOf(Result), #0);
  Done := False;
  try
    Result.dwOSVersionInfoSize := SizeOf(TOSVersionInfoEx);
    Done := GetOSVersionEx(Result);
  except
  end;
  if not(Done) then
  begin
    try
      FillChar(Result, SizeOf(Result), #0);
      Result.dwOSVersionInfoSize := SizeOf(TOSVersionInfo);
      GetVersionEx(OSVersionInfo);
    except
    end;
  end;
end;

function GetWinVersion : string;
var
  OSInfo : TOSVersionInfoEx;
begin
  Result := 'Unbekannte Windows-Version';

  OSInfo := GetOSVersionInfoEx;

  case OSInfo.dwPlatformId of
    VER_PLATFORM_WIN32s:
      begin
        Result := 'Win32s';
      end;
    VER_PLATFORM_WIN32_WINDOWS:
      begin
        if (OSInfo.dwMajorVersion = 4) and (OSInfo.dwMinorVersion = 0) then
          Result := 'Windows 95';
        if (OSInfo.dwMajorVersion = 4) and (OSInfo.dwMinorVersion = 10) then
          Result := 'Windows 98';
        if (OSInfo.dwMajorVersion = 4) and (OSInfo.dwMinorVersion = 90) then
          Result := 'Windows Millennium Edition';
      end;
    VER_PLATFORM_WIN32_NT:
      begin
        if (OSInfo.dwMajorVersion = 4) and (OSInfo.dwMinorVersion = 0) then
          Result := 'Windows NT';
        if (OSInfo.dwMajorVersion = 5) and (OSInfo.dwMinorVersion = 0) then
          Result := 'Windows 2000';
        if (OSInfo.dwMajorVersion = 5) and (OSInfo.dwMinorVersion = 1) then
          Result := 'Windows XP';

        if (OSInfo.dwMajorVersion = 5) and (OSInfo.dwMinorVersion = 2) then
        begin
          if GetSystemMetrics(SM_SERVERR2) <> 0 then
            Result := 'Windows Server 2003 "R2"'
           else
             if (OSInfo.wProductType = VER_NT_WORKSTATION) then
               Result := 'Windows XP x64'
             else
               if OSInfo.wSuiteMask = VER_SUITE_WH_SERVER then
                 Result := 'Windows Home Server'
               else
                 Result := 'Windows Server 2003';
        end;

        if (OSInfo.dwMajorVersion = 6) and (OSInfo.dwMinorVersion = 0) then
        begin
          if (OSInfo.wProductType = VER_NT_WORKSTATION) then
            Result := 'Windows Vista'
          else
            Result := 'Windows Server 2008';
        end;

        if (OSInfo.dwMajorVersion = 6) and (OSInfo.dwMinorVersion = 1) then
        begin
          if (OSInfo.wProductType = VER_NT_WORKSTATION) then
            Result := 'Windows 7'
          else
            Result := 'Windows Server 2008 R2';
        end;

        if (OSInfo.dwMajorVersion = 6) and (OSInfo.dwMinorVersion = 2) then
        begin
          if (OSInfo.wProductType = VER_NT_WORKSTATION) then
            result := 'Windows 8'
          else
            result := 'Windows Server 2012';
        end;


        if (OSInfo.wSuiteMask and VER_SUITE_PERSONAL) = VER_SUITE_PERSONAL then
          Result := Result + ' Home Edition'
        else
          Result := Result + ' Professional';

      end;
  end;
  Result := Trim(Result + ' ' + OSInfo.szCSDVersion);
end;
Was ich nicht verstehe: mein Programm läuft auf einem Windows 7 in einer virtuellen Maschine. Nach der Zeile (OSInfo.dwMajorVersion = 6) and (OSInfo.dwMinorVersion = 1) hab ich in OSInfo.wProductType ein 0 stehen. Ich würde hier eine 1 (=VER_NT_WORKSTATION) erwarten. Was mache ich falsch?

Danke!
Jens
Jens
  Mit Zitat antworten Zitat