Getting Default browser

后端 未结 5 440
轻奢々
轻奢々 2020-12-18 02:58

How can I determine which is the default browser in my system programatically. The code must be developed using vc++ Is there any API for this ?

Where in the regist

5条回答
  •  庸人自扰
    2020-12-18 04:00

    TL;DR: If HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\ exists read that; otherwise read HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\.

    After reading the answers here I found little concensus on how to detect the default browser so I did some experiments and research to figure it out. I downloaded the Firefox source, wrote a script that reads a bunch of registry entries and also ran Process Explorer all while changing the default browser over and over.

    I found there are a lot of registry keys that Firefox and Chrome change when each sets itself as the default browser. I believe Safari and Opera are both similar in behavior. IE appears to change only one of the registry keys I was watching.

    What I found was that while most browsers change other registry paths, all browsers change HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\ (default)

    Here are the registry value from the registry key HKEY_CURRENT_USER\Software\Clients\StartMenuInternet\ (default) while each browser is the default browser.

    • IE 9.0.8112.16421: IEXPLORE.EXE
    • Chrome 21.0.1180.60 m: Google Chrome
    • Firefox 10.0.2: FIREFOX.EXE
    • Safari 3.2.2: Safari.exe
    • Opera 12.01: Opera

    Tested on Microsoft Windows 7 Home Premium SP1 64-bit

    Edit:

    I found on a fresh install of Windows XP SP3 HKEY_CURRENT_USER\SOFTWARE\Clients\StartMenuInternet\ does not exist. In this case you should read the default browser from HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\. I suspect this is also the case on fresh installs of other versions of Windows.

    Addendum:

    The ShellExecute method is a great solution if all you want to do is open a web page in the default browser. However, if you want to, for example, install an extension in only the default browser, ShellExecute does not solve the problem.

提交回复
热议问题