delphi 浏览器操作


//获取默认internet浏览器
function GetDefaultShellHTTP: string;
var
  Reg: TRegistry;
  strWord: string;
begin
  strWord := '';
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;
  if Reg.KeyExists('http\shell\open\command') then
  begin
    Reg.OpenKey('http\shell\open\command',false);
    strWord := Reg.ReadString('');
    Reg.CloseKey;
  end;
  Reg.Free;

  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;
  if Reg.KeyExists('htmlfile\shell\open\command') then
  begin
    Reg.OpenKey('htmlfile\shell\open\command',false);
    strWord := strWord + ',' + Reg.ReadString('');
    Reg.CloseKey;
  end;
  Reg.Free;

  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;
  if Reg.KeyExists('mhtmlfile\shell\open\command') then
  begin
    Reg.OpenKey('mhtmlfile\shell\open\command',false);
    strWord := strWord + ',' + Reg.ReadString('');
    Reg.CloseKey;
  end;
  Reg.Free;

  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;
  if Reg.KeyExists('InternetShortcut\shell\open\command') then
  begin
    Reg.OpenKey('InternetShortcut\shell\open\command',false);
    strWord := strWord + ',' + Reg.ReadString('');
    Reg.CloseKey;
  end;
  Reg.Free;
  Result := strWord;
end; 

//设置自己的internet浏览器
function SetDefaultShellHttp(CmdLine: string): Boolean;
var
  Reg: TRegistry;
begin
  Result := False;
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;   //注册表的地址:
  if Reg.KeyExists('http\shell\open\command') then
  begin
    try
      Reg.OpenKey('http\shell\open\command', True);//注册表的地址:
      Reg.WriteString('', CmdLine);
    finally
      Reg.CloseKey;
    end;
  end;
  Reg.Free;

  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;   //注册表的地址:
  if Reg.KeyExists('htmlfile\shell\open\command') then
  begin
    try
      Reg.OpenKey('htmlfile\shell\open\command', True);//注册表的地址:
      Reg.WriteString('', CmdLine);
    finally
      Reg.CloseKey;
    end;
  end;
  Reg.Free;

  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;   //注册表的地址:
  if Reg.KeyExists('mhtmlfile\shell\open\command') then
  begin
    try
      Reg.OpenKey('mhtmlfile\shell\open\command', True);//注册表的地址:
      Reg.WriteString('', CmdLine);
    finally
      Reg.CloseKey;
    end;
  end;
  Reg.Free;

  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CURRENT_USER;   //注册表的地址:
  if Reg.KeyExists('\SOFTWARE\Clients\StartMenuInternet') then
  begin
    try
      Reg.OpenKey('\SOFTWARE\Clients\StartMenuInternet', True);//注册表的地址:
      Reg.WriteString('', Application.Title);
    finally
      Reg.CloseKey;
    end;
  end;
  Reg.Free;

  //以下是针对Windwos 7 以上的系统作出的方案
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CLASSES_ROOT;   //注册表的地址:
  if Reg.KeyExists('\MicroblueWeb') then
  begin
    try
      Reg.OpenKey('\MicroblueWeb', True);//注册表的地址:
      if not Reg.KeyExists('shell\open\command') then
      begin
        Reg.CreateKey('shell\open\command');
      end;
      Reg.OpenKey('shell\open\command', True);//注册表的地址:
      Reg.WriteString('', CmdLine);
    finally
      Reg.CloseKey;
    end;
  end
  else
  begin
    try
      Reg.CreateKey('MicroblueWeb');
      Reg.OpenKey('\MicroblueWeb', True);//注册表的地址:
      Reg.CreateKey('shell\open\command');
      Reg.OpenKey('shell\open\command', True);
      Reg.WriteString('', CmdLine);
    finally
      Reg.CloseKey;
    end;
  end;  
  Reg.Free;

  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_CURRENT_USER;   //注册表的地址:
  if Reg.KeyExists('\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice') then
  begin
    try
      Reg.OpenKey('\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice', True);//注册表的地址:
      Reg.WriteString('Progid', 'MicroblueWeb');
    finally
      Reg.CloseKey;
    end;
  end;
  Reg.Free;

  Result := True;
end;

//注册自己的浏览器
function RegeditWeb(CmdLine, Path: string): Boolean;
var
  Reg: TRegistry;
begin
  Result := False;
  Reg := TRegistry.Create;
  Reg.RootKey := HKEY_LOCAL_MACHINE;   //注册表的地址:
  if Reg.KeyExists('\SOFTWARE\Clients\StartMenuInternet') then
  begin
    try
      Reg.OpenKey('\SOFTWARE\Clients\StartMenuInternet', True);//注册表的地址:
      if not Reg.KeyExists('\SOFTWARE\Clients\StartMenuInternet\' + CmdLine) then
      begin
        Reg.CreateKey(CmdLine);
      end;
      Reg.OpenKey(CmdLine, True);//注册表的地址:
      Reg.WriteString('', CmdLine);

      if not Reg.KeyExists(CmdLine + '\shell\open\command') then
      begin
        Reg.CreateKey('shell\open\command');
      end;
      Reg.OpenKey('shell\open\command', True);
      Reg.WriteString('', Path);
    finally
      Reg.CloseKey;
    end;
  end;
  Reg.Free;
  Result := True;
end;


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值