Einzelnen Beitrag anzeigen

Benutzerbild von Luckie
Luckie

Registriert seit: 29. Mai 2002
37.621 Beiträge
 
Delphi 2006 Professional
 
#4

Re: VerifyVersionInfo liefert immer False

  Alt 6. Nov 2006, 08:29
Zitat von marabu:
beim Verwerfen des Funktions-Rückgabewertes hast du wohl übersehen, dass das Beispiel im PSDK das Makro verwendet und nicht die API-Funktion
Ächtz. Es war schon spät.

Zitat:
Und die Abfrage von ServicePacks unter XP funktioniert nicht, auch wenn der Platform SDK anderes behauptet. Du wirst es merken, wenn du dein System befragst:
OK, ich habe das Beispiel etwas abgeändert:

Delphi-Quellcode:
type
  DWORDLONG = Int64;

type
  POSVersionInfoEx = ^TOSVersionInfoEx;
  TOSVersionInfoEx = packed record
    dwOSVersionInfoSize: DWORD;
    dwMajorVersion: DWORD;
    dwMinorVersion: DWORD;
    dwBuildNumber: DWORD;
    dwPlatformId: DWORD;
    szCSDVersion: array[0..127] of AnsiChar;
    wServicePackMajor: Word;
    wServicePackMinor: Word;
    wSuiteMask: Word;
    wProductType: Byte;
    wReserved: Byte;
  end;

const
  VER_EQUAL = 1; // The current value must be equal to the specified value.
  VER_GREATER = 2; // The current value must be greater than the specified value.
  VER_GREATER_EQUAL = 3; // The current value must be greater than or equal to the specified value.
  VER_LESS = 4; // The current value must be less than the specified value.
  VER_LESS_EQUAL = 5; // The current value must be less than or equal to the specified value.

  VER_AND = 6; // All product suites specified in the wSuiteMask member must be present in the current system.
  VER_OR = 7; // At least one of the specified product suites must be present in the current system.

  VER_BUILDNUMBER = $0000004; // dwBuildNumber
  VER_MAJORVERSION = $0000002; // dwMajorVersion If you are testing the major version, you must also test
                              // the minor version and the service pack version.
  VER_MINORVERSION = $0000001; // dwMinorVersion
  VER_PLATFORMID = $0000008; // dwPlatformId
  VER_SERVICEPACKMAJOR = $0000020; // wServicePackMajor
  VER_SERVICEPACKMINOR = $0000010; // wServicePackMinor
  VER_SUITENAME = $0000040; // wSuiteMask
  VER_PRODUCT_TYPE = $0000080; // wProductType

function VerifyVersionInfoW(var VersionInfo: TOSVersionInfoEx; TypeMask: DWORD; Conditionalmask: DWORDLONG): BOOL;
  stdcall; external 'kernel32.dll';
function VerSetConditionMask(dwlConditionMask: LONGLONG; TypeBitMask: DWORD; ConditionMask: Byte): LONGLONG; stdcall;
  external 'kernel32.dll';

function IsWinXPOrLater: BOOL;
var
  osvi : TOSVersionInfoEx;
  ConditionMask : DWORDLONG;
  op : Integer;
begin
  op := VER_GREATER_EQUAL;

  ZeroMemory(@osvi, sizeof(TOSVersionInfoEx));
  osvi.dwOSVersionInfoSize := sizeof(TOSVersioNinfoEx);
  osvi.dwMajorVersion := 5;
  osvi.dwMinorVersion := 1;

  ConditionMask := 0;
  ConditionMask := VerSetConditionMask(ConditionMask, VER_MAJORVERSION, op);
  ConditionMask := VerSetConditionMask(ConditionMask, VER_MINORVERSION, op);

  result := VerifyVersionInfoW(osvi, VER_MAJORVERSION or VER_MINORVERSION, ConditionMask);
end;

procedure TForm1.Button1Click(Sender: TObject);
var
  res : BOOL;
begin
  res := IsWinXPOrLater;
  if res then
    ShowMessage('XP oder höher')
  else
    ShowMessage('Nicht Win XP oder höher');
end;
Man sollte so spät nicht mehr programmieren.
Michael
Ein Teil meines Codes würde euch verunsichern.
  Mit Zitat antworten Zitat