Determine the Default Web BrowserBy default, Microsoft Internet Explorer checks to see if it is the default Web browser each time that it starts. If Internet document (HTML) files are associated with a different browser when Internet Explorer starts, Internet Explorer recognizes that it is not the default browser and then prompts you to make it the default browser.
When you select
Make this the default browser in Internet Explorer and in later versions of Netscape, the browser registers itself into all of the following keys to make itself the default browser (among other entries that are written). HKEY_CLASSES_ROOT\.htm HKEY_CLASSES_ROOT\.html HKEY_CLASSES_ROOT\http\shell\open\command HKEY_CLASSES_ROOT\http\shell\open\ddeexec\Application HKEY_CLASSES_ROOT\ftp\shell\open\command HKEY_CLASSES_ROOT\ftp\shell\open\ddeexec\Application HKEY_CLASSES_ROOT\gopher\shell\open\command HKEY_CLASSES_ROOT\gopher\shell\open\ddeexec\Application
Call the ShellExecute API and pass it a URL. That is the easiest way for you to start the default Web browser from your application. If the default Web browser currently runs,
Start the Default Web Browser from Your Application
ShellExecute tells the instance that runs to go to your Uniform Resource Locator (URL). If it is not running,
ShellExecute starts the application and then browses to your URL.
If you used Microsoft Visual C++ to develop your application, the following code describes how to call ShellExecute.
LONG r = ShellExecute(NULL, "open", "http://www.microsoft.com", NULL, NULL, SW_SHOWNORMAL);
ShellExecute declaration in your project. You can find this declaration in the Win32api.txt file that is located in a sub-folder of your Microsoft Visual Studio installation. Optionally, you may copy it from the API Text Viewer tool that comes with Visual Studio 6.0.
To insert the
ShellExecute API into your project, follow these steps:
- Create a new project in Visual Basic.
- Select Standard EXE.
- Add a button to your form.
- Put the following code in the form.
Private Declare Function ShellExecute _
Lib "shell32.dll" _
Alias "ShellExecuteA"( _
ByVal hwnd As Long, _
ByVal lpOperation As String, _
ByVal lpFile As String, _
ByVal lpParameters As String, _
ByVal lpDirectory As String, _
ByVal nShowCmd As Long) _
Private Sub Command1_Click()
Dim r As Long
r = ShellExecute(0, "open", "http://www.microsoft.com", 0, 0, 1)
- Run your project, and then click the button to go to your URL with the default Web browser.
ShellExecute to activate the default Web browser in all Win32 versions of Microsoft Internet Explorer from version 1.0 and later. This technique is not supported on the Microsoft Windows 3.x, UNIX, or on MacIntosh platforms.
How ShellExecute Works
How ShellExecute Interprets the URL PassedShellExecute parses the string that is passed to it so that ShellExecute can extract either a protocol specifier or an extension. Next, ShellExecute looks in the registry and then uses either the protocol specifier or the extension to determine which application to start. If you pass
http://www.microsoft.com to ShellExecute,
ShellExecute recognizes the http:// sub-string as a protocol, which causes ShellExecute to view
HKEY_CLASSES_ROOT\http\shell\open for information about how to run. If you pass myfile.htm to
ShellExecute, ShellExecute recognizes the ".htm" sub-string as an extension. This causes ShellExecute to view HKEY_CLASSES_ROOT\.htm, which leads to
Typically, it is best to fully specify your URL in the string that is passed to ShellExecute, for example:
http://www.microsoft.com instead of
www.microsoft.com. When you fully specify the URL, you make sure that ShellExecute knows exactly which protocol you want. By default, however, ShellExecute detects some patterns that include www.* and ftp.*, and then maps those patterns to the Hypertext Transfer Protocol (HTTP) protocol and the File Transfer Protocol (FTP), respectively.
How ShellExecute Determines Whether to Start a New InstanceWhen ShellExecute looks through the registry, it looks for the shell\open subkey. If the
shell\open\ddeexec key is defined, then a Dynamic Data Exchange (DDE) message with the specified application IExplore and the topic
WWW_OpenURL is broadcast to all top-level windows on the desktop. The first application to respond to this message is the application that goes to the requested URL. If no application responds to this DDE message, then ShellExecute uses the information that is contained in the shell\open\command subkey to start the application. It then re-broadcasts the DDE message to go to the requested URL.
Article ID: 224816 - Last Review: Jul 31, 2007 - Revision: 1