Delphi-PRAXiS

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Win32/Win64 API (native code) (https://www.delphipraxis.net/17-win32-win64-api-native-code/)
-   -   VerifyVersionInfo liefert immer False (https://www.delphipraxis.net/80261-verifyversioninfo-liefert-immer-false.html)

Luckie 6. Nov 2006 00:15


VerifyVersionInfo liefert immer False
 
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? :gruebel:

Basilikum 6. Nov 2006 06:41

Re: VerifyVersionInfo liefert immer False
 
VerSetConditionMask liefert doch einen Rückgabewert, der bei dir nun im nichts versickert...
Delphi-Quellcode:
begin
  op := VER_GREATER_EQUAL;

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

  // Von hier...
  ConditionMask := 0;
  ConditionMask := VerSetConditionMask(ConditionMask, VER_MAJORVERSION, op);
  ConditionMask := VerSetConditionMask(ConditionMask, VER_MINORVERSION, op);
  ConditionMask := VerSetConditionMask(ConditionMask, VER_SERVICEPACKMAJOR, op);
  ConditionMask := VerSetConditionMask(ConditionMask, VER_SERVICEPACKMINOR, op);
  // ...bis hier geändert

  result := VerifyVersionInfoW(osvi, VER_MAJORVERSION or VER_MINORVERSION or VER_SERVICEPACKMAJOR or
    VER_SERVICEPACKMINOR, ConditionMask);
end;
funzt es so ?

marabu 6. Nov 2006 08:07

Re: VerifyVersionInfo liefert immer False
 
Hallo Michael,

beim Verwerfen des Funktions-Rückgabewertes hast du wohl übersehen, dass das Beispiel im PSDK das Makro verwendet und nicht die API-Funktion, aber das hat dir Basilikum ja schon gezeigt. Nur der Ordnung halber - ConditionMask sollte nicht DWORD sondern DWORDLONG sein, hast den Typ doch extra deklariert. 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:

Delphi-Quellcode:
 if not WinXPorLater then ShowMessage(SysErrorMessage(GetLastError));
Übrigens: Der ServicePack-Test (wenn er denn funktionieren würde) und dein Meldungstext harmonieren nicht so ganz.

Freundliche Grüße vom marabu

Luckie 6. Nov 2006 08:29

Re: VerifyVersionInfo liefert immer False
 
Zitat:

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. :wall:

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. ;)

Luckie 6. Nov 2006 09:50

Re: VerifyVersionInfo liefert immer False
 
Liste der Anhänge anzeigen (Anzahl: 1)
So, dafür habe ich das gebraucht: Artikel - Langsam wird es unübersichtlich oder erkennen der Windowsversion ;)

himitsu 22. Sep 2010 11:50

AW: Re: VerifyVersionInfo liefert immer False
 
Toll, da hört man mal auf's MSDN
Zitat:

Zitat von GetVersion
Note: This function has been superseded by MSDN-Library durchsuchenGetVersionEx.
New applications should use MSDN-Library durchsuchenGetVersionEx or MSDN-Library durchsuchenVerifyVersionInfo.

und statt einem Einzeiler hat man nun 6 Zeilen Code, weil man mal dieses MSDN-Library durchsuchenVerifyVersionInfo ausprobieren wollte.
Und Hilfestellungen findet man über Hier im Forum suchenVerifyVersionInfo auch nicht grade sehr oft.

Kein Wunder ... wozu auch umständlich, wenn auch 'nen Einzeiler ausreicht. :wall:


Alle Zeitangaben in WEZ +1. Es ist jetzt 00:09 Uhr.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz