How to find the default browser via the registry on Windows 10

烈酒焚心 提交于 2019-12-22 04:35:25

问题


On versions of Windows prior to Windows 10, I can get the default browser from the following registry key:

HKEY_CURRENT_USER\SOFTWARE\Clients\StartMenuInternet

On Windows 10, I set Microsoft Edge as the default browser. But I don't see any change in the registry key above.

However, on previous versions of Windows it works properly.

How can I get the default browser on Windows 10?


回答1:


Technically StartMenuInternet is not the default browser, it merely determined how the system reacted when you clicked on the Internet icon in the start menu.

In Windows 10, the default application handling is done via the user choice key under:

HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\Shell\Associations\URLAssociations\(http|https)\UserChoice

where (http|https) is one of these e.g. just http or just https

The key ProgId references the handler application id that is invoked when the open for the url is invoked.

The ProgId value can be looked up by key in HKEY_CLASSES_ROOT, and you're looking for the Shell/Open/command default value. For most browsers it will be a simple reference to the executable. You should be able to use the Application key to get the ApplicationName, etc.

Modern applications will reference LaunchWinApp with a DelegateExecute value which specifies the actual application to launch (it's never easy, is it?), the ApplicationName in that case is a reference to a resource in the app (I have no idea how to read those values).

however, why are you looking for this information - if it's merely to open a web page, then you should use the Desktop API (since java 1.6) e.g.:

Desktop.getDesktop().browse(new URI("http://msn.com"));

Gross detail on how to read applications that support a specific url scheme:

On Windows, the control of the default applications is determined by the Default Programs app, this app reads information that applications place in the registry.

There are two places the OS looks for registered applications:

HKEY_CURRENT_USER\SOFTWARE\RegisteredApplications

and

HKEY_LOCAL_MACHINE\SOFTWARE\RegisteredApplications

The entries under those keys are references to a corresponding location in the registry rooted under the same origin as the ResisteredApplications key you're looking at.

e.g. when you install firefox, it places an entry in there labelled Firefox, containing the value Software\Clients\StartMenuInternet\FIREFOX.EXE\Capabilities. This is referencing HKEY_LOCAL_MACHINE\…\Capabilities.

When you look under that location, you will see the key URLAssociations, which specifies the URLs that it handles. When you see both http and https Values, it makes it very likely that this is a web browser. The name of the applications should be obtainable from the ApplicationName value in the Capabilities key. This key can reference localized names, or be the localized name on it's own. Determining the value from an indirection is not trivial (would be worth it's own questions).

You can backtrack from the url's value (e.g. http -> FirefoxURL) to a HKEY_CLASSES_ROOT\FirefoxURL\Shell\Open\Command to get an executable, again remembering that new-ui applications are a special case.



来源:https://stackoverflow.com/questions/32354861/how-to-find-the-default-browser-via-the-registry-on-windows-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!