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 registry is the default browser value stored?
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.
You normally do not need to know this. ShellExecute(0,0,"http://stackoverflow.com",0,0,SW_SHOWNORMAL); will do the trick. Windows will spot the http:// and figure out from there that you want to open a URL. The "default" webbrowser is pretty much defined as the webbrowser used by Windows for this task.
It's not just http:// which is supported. ShellExecute can start the default webbrowser with https:// URLs as well. For mailto: URLs, it starts the default mail client.
you can find the default browser in the registry
i.e. for Windows XP and Vista is located at
HKEY_LOCAL_MACHINE\Software\Clients\StartMenuInternet\
As its name suggests, StartMenuInternet is for registering a Web browser onto the Start Menu (and it only applies to XP and Vista, it is deprecated starting with Windows 7). That does not necessarily establish the browser as the default browser for the entire system. There are many different ways a browser can be registered for different purposes (loading a file, loading a URL, loading data based on a MIME type, etc). Each of those registrations are separate.
Default Programs
How to Register an Internet Browser or Email Client With the Windows Start Menu
Registering an Application to a URL Protocol
File Types
Personally, I would probably look at the registration of the "http" and/or "https" URL handler to determine the default browser, since that will be the app that loads when the user types a URL into the Start Menu or Windows Explorer, or an app passes a URL to ShellExecute/Ex().
Read the default value of HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet and optionally check HKEY_LOCAL_MACHINE\SOFTWARE\Clients\StartMenuInternet\XXX\shell\open\command where XXX is that value picked up from the first key.
Related
Context: I have three web browsers installed on my Windows 10 computer which are Chrome, Firefox, and Opera.
Problem: Whichever browser I newly open, they all start with this website:http://007eecfcfedlkh.jumpkj.chuairan.com/index.html
How it happened: I clicked a link on a website yesterday and it automatically downloaded several applications and automatically installed themselves without showing any instructions to install them.
Thing I have tried: I have reset the browser On startup setting to open my homepage, but it still opens with the aforementioned weird URL.
Thing that may help: Opera browser is very considerate cause it has this option regarding the On startup setting, which is Ask me when Opera is started by a shortcut specifying an URL.
Analysis and need your help: Usually, I start a browser by clicking on the shortcut in Windows start menu, or the shortcut in desktop. This worked normally until the problem appeared. According to Thing that may help, this hostile URL must reside somewhere. Where can I find this unwelcoming shortcut on my computer? How come this shortcut can attach itself to every web browser on my computer? What is the next step I can do to resolve this problem? Is this kind of a virus?
Usually when that happens, you'll have to:
reset the browser settings (or at least reset the startup websites on settings)
go to the browser .exe, open it's properties and remove any flags that were added on the path.
I think you shoud uninstall these applications first.
I've got a Word add-in working well on Windows, and the basics are working on Mac also (Word 2016 both).
What browser does Word 2016 for Mac use?
I see this post:
What browser / browser engine do Office Add-ins use?
But it doesn't explicitly define the way Mac does it.
I see posts about clearing the cache, which is helpful (that will be my next challenge) like How to clear client side browser cache for Excel 2016 Task Pane add-in on Mac?.
Specific reason I'm asking is trying to use Firebase for authentication. On Windows, because Word 2016 uses IE11, clicking Login (with Firebase running the show) in my taskpane pops open IE11...and the login through the full browser is recognized by the Taskpane.
On Mac, clicking Login is opening my default browser...
Alternately I could try to keep the Firebase flow in the Taskpane...but not sure how to do that:)
Mostly curious how Microsoft is kludging this on Mac.
For Mac, the native WebKit control is being used (https://developer.apple.com/reference/webkit/webview). Window.open or other popups will open in the default browser and not share cookies or have window.opener pointer to the WebKit control by default. This does not work in authentication scenarios. If you want the popup window to be opened in a separate WebKit control for authentication, you will need to include the trusted domain in the AppDomain list of the manifest: https://dev.office.com/reference/add-ins/manifest/appdomains. window.opener and cookies should then work between the popup and add-in. The AppDomain list is supported on every platform.
Before Windows 8, the method of adding a mailto: protocol handler was straightforward (as outlined here Register Windows program with the mailto protocol programmatically)
As of Windows 8, the old method no longer works. It would seem that Win8 enforces the following key: HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\URLAssociations\MAILTO\UserChoice.
It also appears the ProgID of the selected app is hashed and can't be forged, at least not that I can tell.
Does anyone have a working method for this, or can point me at a utility class/code that'll outline how to accomplish this programmatically?
For code, any language will do.
Edit
I've been asked from other discussions to specify a use-case, so I think it'd be helpful in the context of this question. Please consider this screenshot https://github.com/shellscape/Gmail-Notifier-Plus/raw/master/Promotional/prefs-account.png and the checkbox allowing the user to specify mailto handling. In this use-case, no one is forcing the user, the user is in control and makes the decision. While windows 8 store apps (metro/modern) have an available app manifest entry that automates the missing process described above, nothing seems to readily exist for desktop apps.
You can set your application to be activated by a custom protocol (like mailto:). When the user installs your app, if there is no other app supporting that protocol, they are not prompted and you are automatically assigned to that protocol.
If, however, the user already has an app that handles that protocol, then they will be prompted with a list of apps who support that protocol with the option to select the default. You cannot force the user to make a specific selection.
Also, if the user clicks on a protocol (like myprotocol:) and they have no app installed that handles that protocol then they will be sent to the store (app) which automatically searches for all apps that support that protocol. The user then installs whatever they want. You cannot force the user to make a specific selection (if any at all).
I wrote an article on protocol activation. It might be interesting to you: http://blog.jerrynixon.com/2012/10/walkthrough-using-windows-8-custom.html
So, I made Desktop Firefox my default mailto handler today in Windows 8 by adding the string value "mailto" to the HKCU\Software\Clients\StartMenuInternet\FIREFOX.EXE\Capabilities\URLAssociations and setting the value of "mailto" equal to the ProgID or "FirefoxURL". I then deleted the keys at HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\URLAssociations\MAILTO\UserChoice to allow me to choose the default client again and this time Firefox was available for me to choose.
The essence of this question seems to be that one cannot take over the default client for any protocol anymore (post Windows 8). The user must choose. However, if you wanted to break the OS convention you could hook the call to create the choose default dialog, which would take research, effort, and be only a temporary kludge and would require "breaking" the OS, or you could send a double click to the dialog to choose for the user, assuming your program has elevated rights so that it can send clicks to Admin windows. That would probably be the easiest way, the user would never know what happened, just a quick flash. Really though, after registering itself as a protocol handler, I don't think any program should go beyond deleting the default protocol handler registry entry, thereby forcing the user to re-choose.
This is how to set mailto protocol manually and simply in Windows 8, 8.1, 2012, 2012R2
Add a new registry branch HKEY_CURRENT_USER\Software\Microsoft\Windows\Shell\Associations\UrlAssociations\mailto\UserChoice
Then click any mailto: link in your web browser, say IE
and finally there in a program list for you to choose which was not available before.
Also MAILTO appears in Control Panel\All Control Panel Items\Default Programs now. There is no other option to add/remove a protocol from there.
You can't have your app directly take over file associations anymore in Windows 8. There are guidelines for how to handle this for both Windows Store and desktop applications here: http://msdn.microsoft.com/en-us/library/windows/apps/hh700321.aspx
Hello, I need to know where/how Windows stores the command that passes the URL clicked in a non-browser program (i.e. Thunderbird) and launches it in the systems default browser.
I need that information to write a script that allows me to have a browser running in a secure sand boxed virtual machine, but still retain the functionality of automatically opening hyperlinks from non-browser programs(i.e. email client on my HOST OS) in the browser of my choosing inside my virtual machine guest OS(xp).
Does anyone know? I'm running Windows Server 2008 R2 if it matters. But I assume most versions of Windows starting with XP, do it the same way.
Thanks
Edit: I found this MS kb article
HKEY_CLASSES_ROOT\http\shell\open\command HKEY_CLASSES_ROOT\http\shell\open\ddeexec
I changed those keys to point to my script, but Firefox on my Host OS still launches, but then complains it is no longer the default browser.
So there must be other registry keys it falls back to besides these.
To open URL in default browser, programs just calls
ShellExecute(0, NULL, "http://...", NULL, NULL, 0)
I am thinking about using the TWebBrowser component that comes within Delphi's default pallet of components in a project, but I wonder if it uses the IE version installed on the client machine?
If yes:
then I guess it would share its history, cookies, workoffline and stuff like that?
Can I separate them somehow?
Is there any webbrowser component that is free and is not shared with Internet Explorer on the client?
The current answer is not quite correct. It appears for compatibility purposes, the WebBrowser control will run in IE7 Standards Mode by default unless you add some registry settings.
See:
WebBrowser Control Rendering Modes in IE8 (archive)
More IE8 Extensibility Improvements (archive)
So it's not quite the current IE version. You can also check this if you use fiddler or check the web server logs for the agent string - as it alters the agent string used too!
Yes, TWebBrowser uses whatever IE version is installed on the machine.
Take a look at this similar thread for some possible alternatives..
How to embed a browser object, other than IE<n>, in a Delphi application
Yes, TWebBrowser is tied to Internet Explorer. If you want a standalone HTML viewer, then look at the PBear components.
TWebBrowser is a wrapper around IE ActiveX interface.
So, in the end,
TWebBrowser = Internet Explorer