如何确定 Windows 默认浏览器(在开始菜单顶部)

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2177957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 07:05:57  来源:igfitidea点击:

How to determine the Windows default browser (at the top of the start menu)

windowsbrowservb6

提问by soupagain

How can I determine the Windows default browser (at the top of the start menu)?

如何确定 Windows 默认浏览器(在开始菜单顶部)?

I am using VB6 but can probably adapt other code no problem.

我正在使用 VB6,但可能可以适应其他代码没问题。

There are similar questions on Stack Overflow, but they seem to provide incorrect answers.

Stack Overflow 上也有类似的问题,但他们似乎提供了不正确的答案。

For instance the key HKEY_LOCAL_MACHINE\Software\Clients\StartMenuInternet\ lists both Internet Explorer and Firefox on my PC.

例如,键 HKEY_LOCAL_MACHINE\Software\Clients\StartMenuInternet\ 列出了我 PC 上的 Internet Explorer 和 Firefox。

And getting the .html association fails for me as well, as HTML files are associated with IE but Firefox is my default browser.

获取 .html 关联对我来说也失败了,因为 HTML 文件与 IE 关联,但 Firefox 是我的默认浏览器。

Note that I don't want to actually open the browser, just get it's name.

请注意,我不想实际打开浏览器,只是获取它的名称。

回答by Piskvor left the building

HKEY_CURRENT_USER\Software\Classes\http\shell\open\command\(Default)is the current user's handler for the HTTP protocol (which means "default browser"; NOTE: this is NOT the same thing as the .htmldefault handler!).

HKEY_CURRENT_USER\Software\Classes\http\shell\open\command\(Default)是当前用户的 HTTP 协议处理程序(这意味着“默认浏览器”;注意:这与.html默认处理程序不同!)。

However, it is possible to have a different browser at the top of Start Menu without changing the default. FYI, the browser executable name in Start menu is stored in HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\(Default).

但是,在不更改默认设置的情况下,可以在“开始”菜单顶部使用不同的浏览器。仅供参考,开始菜单中的浏览器可执行文件名称存储在HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\(Default).

回答by Greg T

Tested in Windows 7 x64: This is a two step process. The user's default browser is in key:

在 Windows 7 x64 中测试:这是一个两步过程。用户的默认浏览器是关键:

HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice\Progid

Common browser Key Name:

常用浏览器键名:

  • IE: IE.AssocFile.HTM
  • FireFox: FirefoxHTML
  • Chrome: ChromeHTML
  • Opera: Opera.HTML
  • IE: IE.AssocFile.HTM
  • 火狐:火狐HTML
  • 铬:ChromeHTML
  • 歌剧:Opera.HTML

Replace <KEY NAME>below with one of the values above to find the executable:

<KEY NAME>下面替换为上面的值之一以查找可执行文件:

HKCR\<KEY NAME>\shell\open\command

Autohotkey script to display the default browser path and executable:

显示默认浏览器路径和可执行文件的 Autohotkey 脚本:

MsgBox % "Default browser: " Browser()

Browser()
{
    ; Find the Registry key name for the default browser
    RegRead, BrowserKeyName, HKEY_CURRENT_USER, Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.html\UserChoice, Progid

    ; Find the executable command associated with the above Registry key
    RegRead, BrowserFullCommand, HKEY_CLASSES_ROOT, %BrowserKeyName%\shell\open\command

    ; The above RegRead will return the path and executable name of the brower contained within qoutes and optional parameters
    ; We only want the text contained inside the first set of quotes which is the path and executable
    ; Find the ending quote position (we know the beginning quote is in position 0 so start searching at position 1)
    StringGetPos, pos, BrowserFullCommand, ",,1

    ; Decrement by one for the StringMid to work correctly
    pos := --pos

    ; Extract and return the path and executable of the browser
    StringMid, BrowserPathandEXE, BrowserFullCommand, 2, %pos%
    Return BrowserPathandEXE
} 

回答by alimbada

Default browsers are usually set on a per user basis. Have you tried HKEY_CURRENT_USER instead? Shows up on mine under there correctly.

默认浏览器通常是基于每个用户设置的。你试过 HKEY_CURRENT_USER 吗?正确地显示在我的下面。