Nie wiem mi się wydaje że lepszym jest sprawdzenie:
//zwraca true jeżeli jest zainstalowany
function IsFlashInstaled: Boolean;
var
reg: TRegistry;
begin
result:= False;
reg:= TRegistry.Create(KEY_READ);
try
reg.RootKey:= HKEY_CLASSES_ROOT;
if reg.OpenKeyReadOnly('CLSID\{D27CDB6E-AE6D-11cf-96B8-444553540000}\InprocServer32') then
begin
result:= FileExists(reg.ReadString(''));
end;
finally
reg.Free;
end;
end;
A tu taka bardziej złożona metoda, którą teraz napisałem /nie za bardzo przetestowana/
function GetFileVersion(path: string): string;
var
VerInfoSize: DWORD;
VerInfo: Pointer;
VerValueSize: DWORD;
VerValue: PVSFixedFileInfo;
Dummy: DWORD;
begin
VerInfoSize := GetFileVersionInfoSize(PAnsiChar(path), Dummy);
GetMem(VerInfo, VerInfoSize);
GetFileVersionInfo(PAnsiChar(path), 0, VerInfoSize, VerInfo);
VerQueryValue(VerInfo, '\', Pointer(VerValue), VerValueSize);
with VerValue^ do
begin
Result := IntToStr(dwFileVersionMS shr 16);
Result := Result + '.' + IntToStr(dwFileVersionMS and $FFFF);
Result := Result + '.' + IntToStr(dwFileVersionLS shr 16);
Result := Result + '.' + IntToStr(dwFileVersionLS and $FFFF);
end;
FreeMem(VerInfo, VerInfoSize);
end;
function GetFlashVersion: string;
var
reg: TRegistry;
flashfile: string;
begin
result:= '';
reg:= TRegistry.Create(KEY_READ);
try
reg.RootKey:= HKEY_CLASSES_ROOT;
if reg.OpenKeyReadOnly('CLSID\{D27CDB6E-AE6D-11cf-96B8-444553540000}\InprocServer32') then
begin
flashfile:= reg.ReadString('');
if FileExists(flashfile) then
result:= GetFileVersion(flashfile);
end;
finally
reg.Free;
end;
end;
//0 takie same
//-1 ver1 > ver2
//1 ver1 < ver2
function CompareFileVersion(ver1, ver2: string): Integer;
type TVersionArray = array [0..3] of Word;
procedure FileVersionToArray(verstr: string; var tab: TVersionArray);
var
sl: TStringList;
i: Integer;
len: Integer;
begin
sl:= TStringList.Create;
try
verstr:= StringReplace(verstr, '.', ',', [rfReplaceAll]);
//sl.Delimiter:= '.';
sl.CommaText:= verstr;
len:= sl.Count - 1;
if (len > High(tab)) then
len:= High(tab);
for i:= 0 to len do
begin
tab[i]:= StrToIntDef(sl[i], 0);
end;
finally
sl.Free;
end;
end;
const
{$J+}
tab1: TVersionArray = (0, 0, 0, 0);
tab2: TVersionArray = (0, 0, 0, 0);
{$J-}
var
i: Integer;
begin
result:= 0;
FileVersionToArray(ver1, tab1);
FileVersionToArray(ver2, tab2);
for i:=0 to 3 do
begin
if tab1[i] > tab2[i] then
begin
result:= -1;
exit;
end;
if tab1[i] < tab2[i] then
begin
result:= 1;
exit;
end;
end;
end;
function MustInstallFalsh(instVer: string): Boolean;
begin
result:= CompareFileVersion(GetFlashVersion, instVer) > 0;
end;
Wywołujesz funkcję MustInstallFalsh podając jako parametr wersje flasha jaka chcesz zainstalować zwróci true jeżeli trzeba instalować (czyli użytkownik nie ma flasha lub ma starszą wersję) false jeżeli ma taką samą lub nowszą. Przykład wywołania:
if MustInstallFalsh('10.1.102.64') then
ShowMessage('Trzeba instalować')
else
ShowMessage('Nie trzeba instalować');
Trochę pokręcona funkcja ale wydaje się powinna działać sprawdzałem u siebie podając przykładowe wersje flasha i niby działa.