How Does Your Browser Know that It’s Not The Default?
On Windows system, how does your browser tell that it’s currently not the default? Prior to Windows Vista, this information is stored in the registry under HKEY_CLASSES_ROOT hive, the usual place where all shell associations are kept. The default browser is maintained under HKEY_CLASSES_ROOT on per-protocol basis (as well as per file type basis, but I’m only interested in the protocols since we use browsers most of the time to access online resources, not offline). The convention for registry locations, where protocol-application associations are stored; is “HKEY_CLASSES_ROOT\[protocol]\shell\open\command “. Substitute [protocol] here with http, https, ftp, gopher or other protocols commonly supported by your favorite browser.
For example: if I want to know what is the default program for opening http protocol, then I’ll look at the registry value of “HKEY_CLASSES_ROOT\http\shell\open\command”. If I go to Start menu, click Run, type “http://newoldthing.wordpress.com” and then hit Enter, the URL will be opened with the application of which command line is registered in this registry value. As simple as that.
The next question will be, whether the default browser is maintained on per-user basis or it’s a system wide setting. If it’s maintained on per-user basis, then if user A set his default browser, then it will not change the default browser for user B or C. This would be somewhat the desired behavior, don’t you think? Imagine a family whose members are computer versed or so they thought, sharing one PC, and they constantly have fight over IE vs Firefox vs Opera. You don’t want the default browser to be system wide setting in that family’s PC.
But unfortunately, the answer is not straightforward. The default browser setting can be both per-user and system-wide. To understand this, you need to understand HKEY_CLASSES_ROOT hive. There’s no better place to start than MSDN documentation. In summary, there are 3 important concepts about HKEY_CLASSES_ROOT that we have to keep in mind:
- The HKEY_CLASSES_ROOT key provides a merged view of “HKEY_LOCAL_MACHINE\Software\Classes” (contains default settings that can apply to all users on the local computer) and “HKEY_CURRENT_USER\Software\Classes” (contains settings that apply only to the current interactive user).
- The user-specific settings have priority over the default settings.
- If you write values to a key under HKEY_CLASSES_ROOT, the values will go under:
- HKEY_CURRENT_USER\Software\Classes; if the key exists under HKEY_CURRENT_USER\Software\Classes.
- Otherwise, HKEY_LOCAL_MACHINE\Software\Classes.
Windows basically requires browsers to do the right thing to make the settings per-user basis instead of system-wide. In ideal scenario, before writing the default browser settings to HKEY_CLASSES_ROOT, browsers need to check if the key already exists under HKEY_CURRENT_USER or not. If the key exists there, then writing to HKEY_CLASSES_ROOT will be equal to committing to HKEY_CURRENT_USER; meaning that the settings will only affect the current interactive user and not other users. If the key doesn’t exist, then no question the key must be written under HKEY_CURRENT_USER instead of HKEY_CLASSES_ROOT. However, most (if not all) browsers basically write to HKEY_CLASSES_ROOT blindly, and since the protocol-association registrations do not exist under HKEY_CURRENT_USER by default, that means browsers write the settings to HKEY_LOCAL_MACHINE all the time. That is not only annoying and disruptive, the attempt to overwrite default browser may ultimately fail as well.
Consider the scenario of standard or limited user accounts. They don’t have write access to HKEY_LOCAL_MACHINE\Software\Classes. So if standard user says “Yes” when asked by browser X to set X as default browser, and X writes the settings to HKEY_CLASSES_ROOT which ultimately passed-through to HKEY_LOCAL_MACHINE; the registry write operation will fail. As a result, browser X will ask the same question next time it’s launched by this standard user. More frustration for the user!
Realizing these bad-eggs and with good intentions to prevent users from stepping on each other’s toes, Windows Vista introduces new way of registering default browser. It’s part of the new feature called Default Programs. It’s different to Windows XP’s SPAD (Set Program Access and Defaults) in that Default Programs is primarily controlled at the per-user level instead of per-machine level (out of the box! And does not rely on 3rd party programs to do the right thing). As part of this Default Programs, the default browser settings are now stored under “HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\[ftp|http|https]“. Windows Vista’s shell will launch a URL with an application associated with the URL’s protocol based on the value of these registry keys. Browsers that were not aware of this change broke on Vista, they were simply unable to set itself as default browser (they saw themselves as default browser although shell didn’t think so because the twos were looking at 2 different registry keys).
Windows shell team introduced a new shell object called ApplicationAssociationRegistration to allow application registering itself as default for a particular type or protocol, as well as querying the current default. This shell object is only available on Vista, and therefore incorporating that in the code that is also targeted for previous Windows versions needs to be done with care. Tomorrow I’ll talk about how to use ApplicationAssociationRegistration shell object in a code base that is not exclusively targeted for Vista.
Posted on March 23, 2007, in Code Junky. Bookmark the permalink. 32 Comments.
Very informative and useful post. I was wondering why HKCR\HTTP\blah doesn’t change when I switch default browsers.
Your post explains it all. I’m using Vista.
Problem solved! Thanks!
Well written article. Thanks
Really its an excellent article. It saved good amout of my work time…
Thanks a lot.
Hmm, I successfully changed my default browser to a batch file I wrote that opens Firefox with a specific profile in XP using the above instructions. Works great. But on Vista I can’t seem to do it. In
“HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\[ftp|http|https]“
I find not application paths but a key called ‘Progid” with the value “FirefoxURL” and I don’t know what to do!
In case of Vista, the Progid key in HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\http stores the required info FirefoxUrl -> Firefox and IE for Internet Explorer
It is a great article, but it lacks a point of clarification, as Aaron pointed out.
Once you open the “HKCU\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\http\UserChoice“, you will find a Progid, representing the User Choice.
With the Progid at hand, you can check the “HKEY_CLASSES_ROOT\[Progid]“, which you then can treat as a normal “http/ftp/https” key from XP.
Hope this helped
Excellent article, thanks for taking the time.
Adam
Thanks a lot
very helpfull and comprehensive article.
manu
Excellent article, thanks.
Thank you very much for this article. It was very helpful for my free software tool (Bestellbuch 3 -> http://www.nogad.de). Now i can open links (helpsystem inside the program) with pointers to a section.
Up to windows xp it comes by itself (link#pointer), on vista or higher, it dont works anymore with shellexecute.
With best regards
~Mathias
Thank you for your very helpful article. I first thought I had to go to “the old new thing” blog to find this information ;o)
Informative article. Thanks for that.
Thanks buddy,
“HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\ Associations\UrlAssociations\[ftp|http|https]“
Really its a very straight forward key’s to change the default web browser.
What is the similar registry key in Windows XP to change the default web browser?
Thank you. You’ve cleared up a deep dark mystery.
[...] How Does Your Browser Know that It’s Not The Default? « The New Old Thing [...]
Thanks, this was very helpful
This is a great article! Thanks for taking the time to write it up and post it!
Very well written and instructive. What if I put a shortcut to portable chrome and rename it chrome.exe on login and then replace it with the local chrome path whenI log off? I know nothing about windows, but I assume that would be a relatively easy script/batch file to write?
check this site: http://djseppie.wordpress.com/2012/10/22/set-internet-explorer-as-default-browser-through-registry/
Thanks for this article. You answered my question for Windows 7.
You could definitely see your expertise within the work you write.
The sector hopes for even more passionate writers like you who are not afraid to mention how they
believe. Always follow your heart.
What a data of un-ambiguity and preserveness of precious experience regarding unexpected emotions.
Hi, I do think this is a great site. I stumbledupon it
I will revisit once again since I book-marked it.
Money and freedom is the greatest way to change, may you be rich and continue to help others.
I was recommended this blog by my cousin. I am not sure whether this post
is written by him as no one else know such detailed about my problem.
You are amazing! Thanks!
My website siemens simatic s7 200
First off I would like to say superb blog! I had a
quick question which I’d like to ask if you do not mind. I was curious to know how you center yourself and clear your head before writing. I have had a tough time clearing my thoughts in getting my ideas out there. I do take pleasure in writing however it just seems like the first 10 to 15 minutes are generally lost just trying to figure out how to begin. Any ideas or hints? Thanks!
My website komunikacja profibus
Nice blog! Is your theme custom made or did you download it from somewhere?
A design like yours with a few simple tweeks would really make my blog shine.
Please let me know where you got your design. Appreciate it-
http://zvacseniepenisux.com/
rgrds hl3c53yx
I feel this is among the most significant information for me.
And i’m happy reading your article. But wanna statement on few normal issues, The web site style is ideal, the articles is actually excellent : D. Just right process, cheers
Pingback: Teknovis » Firefox Default Browser
Pingback: XP login script dat IE default browers maakt - 9lives
Pingback: Default browser « Hoa Chau’s weblog
Pingback: What is the registry setting required to set Internet Explorer as the default browser? Drija
Pingback: What is the registry setting required to set Internet Explorer as the default browser? - Admins Goodies