Ich habe die
API-Funktion VerifyVersionInfo
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 : DWORD;
op : Integer;
begin
ConditionMask := 0;
op := VER_GREATER_EQUAL;
ZeroMemory(@osvi, sizeof(TOSVersionInfoEx));
osvi.dwOSVersionInfoSize := sizeof(TOSVersioNinfoEx);
osvi.dwMajorVersion := 5;
osvi.dwMinorVersion := 1;
osvi.wServicePackMajor := 2;
osvi.wServicePackMinor := 0;
VerSetConditionMask(ConditionMask, VER_MAJORVERSION, op);
VerSetConditionMask(ConditionMask, VER_MINORVERSION, op);
VerSetConditionMask(ConditionMask, VER_SERVICEPACKMAJOR, op);
VerSetConditionMask(ConditionMask, VER_SERVICEPACKMINOR, op);
result := VerifyVersionInfoW(osvi, VER_MAJORVERSION or VER_MINORVERSION or VER_SERVICEPACKMAJOR or
VER_SERVICEPACKMINOR, ConditionMask);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
res : BOOL;
begin
res := IsWinXPOrLater;
if res then
ShowMessage('XP SP1 oder höher')
else
ShowMessage('Nicht Win XP SP1 oder höher');
end;
Aber die liefert mir immer False zurück, obwohl ich Windows XP SP2 habe, wo sie eigentlich True liefern sollte. Woran liegt das?