您可以使用获取文件版本信息的方法。首先我们会得到iexplore.exe
路径。
function GetIEPath: string;
var
Reg: TRegistry;
Len: Integer;
begin
Result := '';
Reg := TRegistry.Create;
with Reg do
begin
try
RootKey := HKEY_CLASSES_ROOT;
OpenKeyReadOnly('CLSID\{0002DF01-0000-0000-C000-000000000046}\LocalServer32');
try
Result := ReadString('');
finally
CloseKey;
Len := Length(Result);
if Len >= 2 then
begin
if(Result[Len] = '"') then
Delete(Result, Len, 1);
if(Result[1] = '"') then
Delete(Result, 1, 1);
end
else
begin
Result := '';
end;
end;
finally
Free;
end;
end;
end;
{0002DF01-0000-0000-C000-000000000046}
是 Internet Explorer 的 CLSID。的默认键值为LocalServer32
路径iexplore.exe
。
然后,我们使用一些 API 调用,如 Simon Grossenbacher 在此链接上演示的那样,来获取文件版本信息。修改他的函数,我们得到这个:
function GetIEVersion: string;
var
IEPath: string;
VerInfoSize: DWORD;
VerInfo: Pointer;
VerValueSize: DWORD;
VerValue: PVSFixedFileInfo;
Dummy: DWORD;
begin
Result := '0';
IEPath := GetIEPath;
if IEPath = '' then
Exit;
VerInfoSize := GetFileVersionInfoSize(PChar(IEPath), Dummy);
if VerInfoSize = 0 then
Exit;
GetMem(VerInfo, VerInfoSize);
GetFileVersionInfo(PChar(IEPath), 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;
然后,您只需使用,例如,这个:
ShowMessage(GetIEVersion);