开发者

How do you get the currently installed version of IE with Delphi?

开发者 https://www.devze.com 2023-01-07 01:27 出处:网络
How can I get the version IE installed in my computer? I\'ve figured out a work-around on my problem so that I don\'t have to check for the version of the currently installed IE anymore. Thanks for

How can I get the version IE installed in my computer?


I've figured out a work-around on my problem so that I don't have to check for the version of the currently installed IE anymore. Thanks for the answe开发者_运维问答rs though. :)


uses
  Registry;

function GetIEVersion : string;
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    Reg.OpenKeyReadOnly('Software\Microsoft\Internet Explorer');
    try
      Result := Reg.ReadString('Version');
    except
      Result := '';
    end;
    Reg.CloseKey;
  finally
    Reg.Free;
  end;
end;

This function should return the currently installed version number of IE.


I would update mentioned here answers, an old one and MS KB.

First key:

Microsoft lies about the version value in IE10 to avoid breaking programs that can only recognize a single digit version number. A more (hackish) way is to check IE version is to check the file version of mshtml.dll – Sheng Jiang 蒋晟 Sep 11 '13 at 0:06

Second key:

In newer version IE 10 and 11 true version is recorded in value 'svcVersion' and value 'Version' contains at the beginning '9.'

All these follows to code

function GetIEVersion: string;
begin
  with TRegistry.Create do
  try
    RootKey := HKEY_LOCAL_MACHINE;
    OpenKeyReadOnly('Software\Microsoft\Internet Explorer');
    try
      Result := ReadString('svcVersion');
      if Result.IsEmpty then Result := ReadString('Version');
      if Result.IsEmpty then raise Exception.Create('');
    except
      Result := '0';
    end;
    CloseKey;
  finally
    Free;
  end;
end;


uses Registry;

function GetIEVersion(AOnlyMajorVersion: Boolean = False): string;
var
   lVersao: string;
   lReg: TRegistry;
begin
   Result := '';

   lReg := TRegistry.Create;

   try

      lReg.RootKey := HKEY_LOCAL_MACHINE;

      if lReg.OpenKeyReadOnly('Software\Microsoft\Internet Explorer') then
      begin
         lVersao := '';

         if lReg.ValueExists('svcVersion') then
         begin
            lVersao := lReg.ReadString('svcVersion');
         end
         else if lReg.ValueExists('Version') then
         begin
            lVersao := lReg.ReadString('Version');
         end
         else if lReg.ValueExists('IVer') then
         begin
            lVersao := lReg.ReadString('IVer');
         end;

         if (lVersao <> '') then
         begin
            if (AOnlyMajorVersion) then
            begin
               if (WordCount(lVersao, ['.']) > 0) then
               begin
                  lVersao := ExtractWord(1, lVersao, ['.']);
               end;
            end;
         end;

         Result := Trim(lVersao);

         lReg.CloseKey;
      end;

   finally
      lReg.Free;
   end;
end;


uses
  Registry;

function GetIEVersion(Key: string): string;
var
  Reg: TRegistry;
begin
  Reg := TRegistry.Create;
  try
    Reg.RootKey := HKEY_LOCAL_MACHINE;
    Reg.OpenKey('Software\Microsoft\Internet Explorer', False);
    try
      Result := Reg.ReadString(Key);
    except
      Result := '';
    end;
    Reg.CloseKey;
  finally
    Reg.Free;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  ShowMessage('IE-Version: ' + GetIEVersion('Version')[1] + '.' + GetIEVersion('Version')[3]);
  ShowMessage('IE-Version: ' + GetIEVersion('Version'));
end;

Source: http://www.vbforums.com/showthread.php?t=342893

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号