Microsoft KB Archive/283225

= How To Start Internet Explorer from a Java Application =

Article ID: 283225

Article Last Modified on 6/14/2006

-

APPLIES TO


 * Microsoft Software Development Kit for Java 4.0
 * Microsoft Internet Explorer 5.0
 * Microsoft Internet Explorer 5.01
 * Microsoft Internet Explorer 5.5 Service Pack 1

-



This article was previously published under Q283225



SUMMARY
It has been widely documented on the Internet that you should use the following code to start your default browser from a Java application: rundll32 url.dll,FileProtocolHandler http://www.microsoft.com/ms.htm However, when Internet Explorer is identified as your default browser, you receive the following error message:

Unable to open &quot;http://www.microsoft.com/ms.htm&quot;.

This code does work if you do not specify the page as follows: rundll32 url.dll,FileProtocolHandler http://www.microsoft.com/ NOTE: This solution is considered obsolete. It is now documented that you should use the ShellExecute function.



MORE INFORMATION
The following code samples demonstrate two possible solutions for the above-mentioned procedure.

Solution Using the ShellExecute function
The following code uses the ShellExecute function: import com.ms.com.*; import com.ms.win32.*; import java.io.*; import com.ms.lang.*; import com.ms.wfc.html.om.shdocvw.*;

/** * @com.register ( clsid=A1902ECA-A3B2-4DD5-840B-648CE61D48E6, typelib=631CF9B2-7570-4119-8703-634B4F847897 ) */ public class BrowserLaunch {  public static void main (String[] args) {     try {        BrowserLaunch app = new BrowserLaunch; String defBrowser = app.checkDefaultBrowser; app.launchDefault(&quot;http://www.microsoft.com/ms.htm&quot;); }     catch(Exception e)      { System.out.println(e.getMessage); }  }

public String checkDefaultBrowser throws Exception {     //HKEY_CLASSES_ROOT\http\shell\open\ddeexec\Application RegKey rkey = new RegKey(RegKey.CLASSES_ROOT, http\\shell\\open\\ddeexec\\Application&quot;, RegKey.KEYOPEN_READ);

return rkey.getStringValue(&quot;&quot;); }

public void launchDefault(String file) throws Exception {     int retval; retval = Shell32.ShellExecute(0,&quot;open&quot;,file,null,null,wins.SW_SHOWNORMAL);

if (retval <= 32) alert(&quot;Problem with URL.&quot;); }

private void alert(String msg) {     User32.MessageBox(0,msg,&quot;Alert!&quot;,winm.MB_OK); } }

Solution Using the Runtime Class
The following code uses the Runtime class: import java.io.IOException; import com.ms.com.*; import com.ms.lang.*;

public class Class1 {  /**    * This is the main entry point for the application. *   * @param args Array of parameters are passed to the application * through the command line. */   public static void main (String[] args) throws Exception {     Class1 app = new Class1; String defBrowser = app.checkDefaultBrowser; if (defBrowser.equalsIgnoreCase(&quot;IExplore&quot;)) try {        Runtime rt = Runtime.getRuntime; String path = app.getBrowserExecutablePath; //Process a = rt.exec(&quot;c:\\Program Files\\Internet Explorer\\iexplore http://www.microsoft.com/ms.htm&quot;); Process a = rt.exec(path + &quot;http://www.microsoft.com/ms.htm&quot;); }      catch(Exception e)       { System.out.println(e); }   }

public String checkDefaultBrowser throws Exception {     //HKEY_CLASSES_ROOT\http\shell\open\ddeexec\Application RegKey rkey = new RegKey(RegKey.CLASSES_ROOT, &quot;http\\shell\\open\\ddeexec\\Application&quot;, RegKey.KEYOPEN_READ); return rkey.getStringValue(&quot;&quot;); }

public String getBrowserExecutablePath throws Exception {     //HKEY_CLASSES_ROOT\http\shell\open\command\default RegKey rkey = new RegKey(RegKey.CLASSES_ROOT, &quot;http\\shell\\open\\command&quot;,RegKey.KEYOPEN_READ);

return rkey.getStringValue(&quot;&quot;); } }

