21

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?

Patrice M.
  • 4,209
  • 2
  • 27
  • 36
Phạm Quốc Bảo
  • 864
  • 2
  • 10
  • 19
  • fiddling with the registry on windows is ALWAYS the worst possible thing to do - and its almost always completely unnecessary. Like has already been mentioned, the [Desktop API](https://docs.oracle.com/javase/7/docs/api/java/awt/Desktop.html) is a good choice, but be sure to evaluate [isDesktopSupported](https://docs.oracle.com/javase/7/docs/api/java/awt/Desktop.html#isDesktopSupported()) – specializt Sep 02 '15 at 14:15
  • @specialist: Thanks, I want to launch the url by specific browser which is installed on my computer.. I research but I don't see API support to detect the browsers by java code... – Phạm Quốc Bảo Sep 02 '15 at 16:09
  • because its impossible, regardless of the used language. – specializt Sep 02 '15 at 18:28

3 Answers3

44

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.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
  • I wan to list out all browser installed on my computer, so I think the registry window can help me.. Do you have another way that can detect all browser ??? – Phạm Quốc Bảo Sep 02 '15 at 14:13
  • it is impossible to "detect all browsers" because there is no such registration API - only one HANDLER may be registered for a single protocol and thats about it. Windows is not Android, if you want to find certain applications you need to explicitly search for them - via heuristic path patterns and probably directory contents ... but that will be highly unreliable - even searching for vendor-specific registry settings is highly unreliable ... its best to forget about your task altogether because it will never work 100%. – specializt Sep 02 '15 at 14:19
  • @specialist: How about default browser ? we can detect/get name default browser from registry or another way?? – Phạm Quốc Bảo Sep 02 '15 at 14:34
  • There is no default browser, there is only the default handler for `http`, `https`, etc. protocols. You could in theory have separate browsers for unsafe web-browsing and 'safe' web-browsing; but in general the default `http` handler is probably the web-browser. – Anya Shenanigans Sep 02 '15 at 14:37
  • 1
    @Petesh: Thanks so much.. I think HKEY_CLASSES_ROOT\http\shell\open\command can help me. But I'm not sure 100% it works well..=)) – Phạm Quốc Bảo Sep 02 '15 at 14:42
  • It will definitely give you the program that handles `http` urls. I'll detail how the `Default Programs` information is organized so you could try to determine all programs that can handle, for example, `http`, `https` - it's a bit long – Anya Shenanigans Sep 02 '15 at 14:46
  • @Petesh: It works not well. I set the IE is default browser, but the HKEY_CLASSES_ROOT\http\shell\open\command shows chrome.exe.....I try to with multi browsers but cannot work properly.... – Phạm Quốc Bảo Sep 02 '15 at 15:15
  • @PhạmQuốcBảo my bad on the http - it's overridden by the ProgId in `HKEY_CURRENT_USER\Microsoft\Windows\Shell\Associations\UlAssociations\http\UserChoice\ProgId` - this references the relevant class in the classes tree. – Anya Shenanigans Sep 02 '15 at 15:44
  • @Petesh: Thank you, It 's useful for me...=) – Phạm Quốc Bảo Sep 02 '15 at 16:04
  • To prevent Group Policy from changing this, open the Advanced Permissions window for each respective `UserChoice` key and remove `Full Control` permissions from the `SYSTEM` user. You will have to disable and copy the inherited permissions to do this. – Chiramisu Jan 24 '22 at 21:43
  • Thank you for teaching us to fish! – Chiramisu May 07 '22 at 02:10
2

Found a solution if none of these others are working. I had an issue where window's default browser directory for chromium (portable version at chromium.woolyss.com) was at the downloads folder and windows had not detected the missing executable for the default browser, icon was missing too in w10 settings.

After trying many things I eventually got a fix, updating the directory values at

Computer\HKEY_CLASSES_ROOT\Chromium(randomstring)\shell\open\command

at "\HKEY_CLASSES_ROOT\Chromium(randomstring)\" the random letters/numbers at the end of chromium will be different for everyone im assuming so just look for chromium and you'll see it.

nordicvf
  • 21
  • 1
2

Everyone here is spelunking the undocumented registry. You should not be doing that.

Instead you should be using the intended, supported, API function: AssocQueryString

Conceptually the call is:

AssocQueryString(0, ASSOCSTR_EXECUTABLE, ".html", path, sizeof(path));

Which on my machine returns:

C:\Program Files (x86)\Google\Chrome\Application\chrome.exe

Example code (pseudocode)

String GetDefaultBrowser()
{
   String path;
   DWORD nChars = 1024;

   //Allocate enough space to hold nChars
   SetLength(path, nChars);

   HRESULT hr = AssocQueryString(ASSOCF_NONE, ASSOCSTR_EXECUTABLE, ".html", null, path), ref nChars);
   if (hr == E_POINTER)
   {
      //Buffer was too small; try again with larger size
      SetLength(path, nChars);
      hr = AssocQueryString(ASSOCF_NONE, ASSOCSTR_EXECUTABLE, ".html", null, path), ref nChars);
   }
   if (Failed(hr)) throw new COMException(hr);

   //Set the string buffer to size
   SetLength(path, nChars-1); // don't include the null terminator

   return path;
}

Bonus Chatter

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219