Delphi 设置系统默认浏览器为IE

设置默认浏览器的功能其实还是通过修改注册表项来实现,本文的例子中使用了完整的Delphi源码来实现该功能,且不需要重启机器。

百度各种资料会发现,基本上给出的答案都是修改HKEY_CLASSES_ROOT\HTTP\Shell\open\command就可以,可是经过我的多次验证——呵呵,并不行。

于是又重新搜索了各种资料,终于让我找到了:

procedure TForm1.SetDefaultIE;
var
  reg: TRegistry;
  IEPath: string;
begin
  reg := TRegistry.Create;
  reg.RootKey := HKEY_LOCAL_MACHINE;
  IEPath := GetAppPath('IEXPLORE.EXE');
  if IEPath = '' then
  begin
    log4debug('未找到IE浏览器的安装路径,请检查!');
    Exit;
  end;
  reg.CloseKey;
  reg.RootKey := HKEY_CLASSES_ROOT;
  try
    // 写HKEY_CLASSES_ROOT\http\shell\open\command
    if reg.OpenKey('\WebMind', True) then
      reg.WriteString('', 'WebMind Document');
    reg.CloseKey;
    reg.RootKey := HKEY_CLASSES_ROOT;
    if reg.OpenKey('\WebMind\Shell\open\command', True) then
    begin
      reg.WriteString('', '"' + IEPath + '" ' + '"%1"');
      reg.CloseKey;
    end;
    reg.CloseKey;
    reg.RootKey := HKEY_CURRENT_USER;
    if reg.OpenKey
      ('\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice',
      True) then
      reg.WriteString('Progid', 'IE.HTTP');
  finally
    reg.CloseKey;
    reg.Free;
  end;
end;

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值