inno-setup - Inno Setup 获取默认浏览器
问题描述
我有一个需要在用户计算机上安装默认浏览器的软件。
有没有办法让我得到它?
谢谢
解决方案
在现代版本的 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;
推荐阅读
- php - 通过 Sendgrid 将表单数据作为 PDF 附件发送
- c++ - 如何在最后的排序双向链表中插入节点?
- vue.js - VueJS SideMenuBar 组件
- python - 列表列表(二维数组)迭代和赋值
- c - 值开头的 0 未显示在输出中
- oracle - ORA-28547: 与服务器的连接失败,可能是 Oracle 网络管理员错误,但在重新启动后可以正常工作
- c - c 包含指令中的 linux 内核源代码树——它是如何工作的
- ms-access - Access 警告查询中的 case 子句存在运算符错误
- javascript - 赛普拉斯拆分字符串进行测试
- reactjs - 在 React Router 中使用 Link 和 NavLink 传递道具的问题