列出安装在Windows计算机上的所有网络浏览器 [英] List all web-browsers installed on a Windows machine

查看:139
本文介绍了列出安装在Windows计算机上的所有网络浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一个通用方式/ API列出所有Web浏览器(名称,可执行的,默认是/否)安装在我的机器上(每用户),以及如何找出哪些是默认Web浏览器?

Is there a common method/api to list all web browsers (name, executable, default yes/no) installed on my machine (and per user), and how to find out which is the default web browser?

我已经看到了这个问题:如何找到安装在计算机上的所有浏览器

I have seen this question: How to find all the browsers installed on a machine

和MSDN上:如何注册一个Internet浏览器或电子邮件客户端,其中列明了Windows开始菜单的网络浏览器的的注册自己在 HKLM \\ SOFTWARE \\客户\\ StartMenuInternet (和 HKCU

And on MSDN: How to Register an Internet Browser or Email Client With the Windows Start Menu which states that web-browsers should register themselves under HKLM\SOFTWARE\Clients\StartMenuInternet (and HKCU)

那真的是普通/正确的做法? (如果是,任何固体实施了吗?)

Is that really the common/correct approach? (And if yes, any solid implementation out there?)

我的目标是创建一个安装用户机器上的所有网页浏览器的列表(表示默认)下拉菜单,允许用户浏览他的HTML文件/网址与外部网络的浏览器之一可用。

My goal is to create a drop-down menu with a list of all web-browsers installed on user's machine (indicating the default), and allow the user to browse his HTML file/URLs with one of the external web-browser available.

推荐答案

您可以做类似

procedure ListRegisteredBrowsers(List: TStrings);
var
  reg: TRegistry;
  ki: TRegKeyInfo;
  i: Integer;
  keyname: string;
  len: DWORD;
begin
  reg := TRegistry.Create;
  try
    reg.RootKey := HKEY_LOCAL_MACHINE;
    if not Reg.KeyExists('\SOFTWARE\Clients\StartMenuInternet') then Exit;
    if not Reg.OpenKey('\SOFTWARE\Clients\StartMenuInternet', false) then
      raise Exception.Create('ListRegisteredBrowsers: Could not open registry key.');
    if not reg.GetKeyInfo(ki) then
      raise Exception.Create('ListRegisteredBrowsers: Could not obtain registry key information.');
    List.Clear;
    SetLength(keyname, len);
    for i := 0 to ki.NumSubKeys - 1 do
    begin
      len := ki.MaxSubKeyLen + 1;
      if RegEnumKeyEx(reg.CurrentKey, i, PChar(keyname), len, nil, nil, nil, nil) <> ERROR_SUCCESS then
        RaiseLastOSError;
      if reg.OpenKey('\SOFTWARE\Clients\StartMenuInternet\' + keyname, false) then
        List.Add(reg.ReadString(''));
      Reg.OpenKey('\SOFTWARE\Clients\StartMenuInternet', true);
    end;
  finally
    reg.Free;
  end;
end;

function GetDefaultBrowser: string;
var
  reg: TRegistry;
begin
  result := '';
  reg := TRegistry.Create;
  try
    reg.RootKey := HKEY_CURRENT_USER;
    if Reg.OpenKey('\SOFTWARE\Clients\StartMenuInternet', false) then
      result := reg.ReadString('')
    else
    begin
      reg.RootKey := HKEY_LOCAL_MACHINE;
      if Reg.OpenKey('\SOFTWARE\Clients\StartMenuInternet', false) then
        result := reg.ReadString('')
    end;
    reg.RootKey := HKEY_LOCAL_MACHINE;
    if Reg.OpenKey('\SOFTWARE\Clients\StartMenuInternet\' + result, false) then
      result := reg.ReadString('');
  finally
    reg.Free;
  end;
end;

测试吧:

procedure TForm1.Button1Click(Sender: TObject);
var
  sl: TStringList;
  i: Integer;
  DefBrw: string;
begin
  DefBrw := GetDefaultBrowser;
  sl := TStringList.Create;
  try
    ListRegisteredBrowsers(sl);
    Memo1.Lines.BeginUpdate;
    for i := 0 to sl.Count - 1 do
      if SameText(sl[i], DefBrw) then
        Memo1.Lines.Add(sl[i] + ' (Default)')
      else
        Memo1.Lines.Add(sl[i]);
    Memo1.Lines.EndUpdate;
  finally
    sl.Free;
  end;
end;

这篇关于列出安装在Windows计算机上的所有网络浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆