首页 > 解决方案 > Inno Setup 获取默认浏览器

问题描述

我有一个需要在用户计算机上安装默认浏览器的软件。

有没有办法让我得到它?

谢谢

标签: inno-setuppascalscript

解决方案


在现代版本的 Windows 上正确运行的解决方案不能基于与http协议的关联,因为这不再可靠。它应该基于一个解决方案,例如@GregT 对如何确定 Windows 默认浏览器(在开始菜单顶部)的回答。

所以像:

function GetBrowserCommand: string;
var
  UserChoiceKey: string;
  HtmlProgId: string;
begin
  UserChoiceKey :=
    'Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice';
  if RegQueryStringValue(HKCU, UserChoiceKey, 'ProgId', HtmlProgId) then
  begin
    Log(Format('ProgID to registered for .html is [%s].', [HtmlProgId]));
    if RegQueryStringValue(HKCR, HtmlProgId + '\shell\open\command', '', Result) then
    begin
      Log(Format('Command for ProgID [%s] is [%s].', [HtmlProgId, Result]));
    end;
  end;

  { Fallback for old version of Windows }
  if Result = '' then
  begin
    if RegQueryStringValue(HKCR, 'http\shell\open\command', '', Result) then
    begin
      Log(Format('Command registered for http: [%s].', [Result]));
    end;
  end;
end;

如果要从命令中提取浏览器路径,请使用如下代码:

function ExtractProgramPath(Command: string): string;
var
  P: Integer;
begin
  if Copy(Command, 1, 1) = '"' then
  begin
    Delete(Command, 1, 1);
    P := Pos('"', Command);
  end
    else P := 0;

  if P = 0 then
  begin
    P := Pos(' ', Command);
  end;
  Result := Copy(Command, 1, P - 1);
end;

(基于在 Inno Setup 中执行 UninstallString


推荐阅读