Invoking a url in System's default browser

Hi All!
I have one question related to invoking an url in a browser using Runtime.getRuntime()
I am using the command as
command = "rundll32 url.dll,FileProtocolHandler " + url;
Runtime.getRuntime().exec(command);
where url = (say) http://www.java.sun.com
This works perfectly fine for internet and intranet and intranet.
But if my url has spaces (more than one ) it fails.
e.g. url = "fileserver:\\Temp 12\read.html
Now the folder is "Temp 12" having two gaps inbetween Temp and 12.
I tried to use exec(String [] cmdArray)
but it gives me error as "java.io.IOException: CreateProcess: www.hotmail.com "cmd /c start" error=2"
Where cmdArray is defined as
String[] cmdArray =
("rundll32 url.dll, ileProtocolHandler " + url)
Any suggesstion or help.
Anand

I ran into the same problem, and found solutions at:
http://ostermiller.org/utils/Browser.html

Similar Messages

  • Invoking system's default browser

    Hi
    While developing a swing application, in event handling, I would like to open a HTML file in the system's default browser like IE or netscape. Can I know how to do that?

    I use the system command
    rundll32 url.dll,FileProtocolHandler http://java.sun.com
    but if the URL represents a known mime type then the browser doesn't launch. That's weird but you can get around it by suffixing the URL with a "#" character.

  • Launch URL on user's default browser

    Hello,
    Is it possible to launch a URL on the user's default browser, through an ActionListener? Something like:
    public void actionPerformed(ActionEvent e) {
            JMenuItem source = (JMenuItem)(e.getSource());
            if(source.getText().equals("Online Help"))
              //launch URL here
    }Thanx in advance! :)

    Hi Derelict, check this out:
    http://browserlauncher.sourceforge.net/Hope it's helpful!
    Chris.

  • How do you invoke the default browser for Unix/OSX

    Does anyone know how to programmatically display the contents of a URL in the default browser for a Unix system? I found a javaworld article on doing this using Runtime.getRuntime().exec(cmd). The article gives the cmd string for invoking the default browser in Windows, and for invoking the Netscape browser in Unix.
    This can easily be extended to invoke any known browser executable in a known path on a Unix system; but I'd like to invoke the default browser without knowing what or where it is. I'm specifically targetting Mac/OSX, but any Unix solution is worth trying.
    Is there a Unix command for launching the default browser to display the contents of a given URL? Or is there an alternative approach, rather than invoking Runtime.exec()?
    -Mark

    After extensive google searching, I came across a partial solution. This code detects the default browser on a Mac, and provides an elegant solution for trying standard browsers in turn for other Unix systems. I tested it on WIndows XP and Mac OSX 3.9, and it detected the default browser each time. A suped up version of this tool is available as a SourceForge project. You can find it here:
    http://sourceforge.net/projects/browserlaunch2/
    Here's the simplified code:
    //  Bare Bones Browser Launch                          //
    //  Version 1.5                                        //
    //  December 10, 2005                                  //
    //  Supports: Mac OS X, GNU/Linux, Unix, Windows XP    //
    //  Example Usage:                                     //
    //     String url = "http://www.centerkey.com/";       //
    //     BareBonesBrowserLaunch.openURL(url);            //
    //  Public Domain Software -- Free to Use as You Like  //
    import java.lang.reflect.Method;
    import javax.swing.JOptionPane;
    public class BareBonesBrowserLaunch {
       private static final String errMsg = "Error attempting to launch web browser";
       public static void openURL(String url) {
          String osName = System.getProperty("os.name");
          try {
             if (osName.startsWith("Mac OS")) {
                Class fileMgr = Class.forName("com.apple.eio.FileManager");
                Method openURL = fileMgr.getDeclaredMethod("openURL",
                   new Class[] {String.class});
                openURL.invoke(null, new Object[] {url});
             else if (osName.startsWith("Windows"))
                Runtime.getRuntime().exec("rundll32 url.dll,FileProtocolHandler " + url);
             else { //assume Unix or Linux
                String[] browsers = {
                   "firefox", "opera", "konqueror", "epiphany", "mozilla", "netscape" };
                String browser = null;
                for (int count = 0; count < browsers.length && browser == null; count++)
                   if (Runtime.getRuntime().exec(
                         new String[] {"which", browsers[count]}).waitFor() == 0)
                      browser = browsers[count];
                if (browser == null)
                   throw new Exception("Could not find web browser");
                else
                   Runtime.getRuntime().exec(new String[] {browser, url});
          catch (Exception e) {
             JOptionPane.showMessageDialog(null, errMsg + ":\n" + e.getLocalizedMessage());
       }

  • How to check whether a default browser is opened in the operating system?

    Hi,
    I am newbie here. During my work, I faced an interesting problem. I need to:
    - check whether a default html browser is opened;
    - check whether the browser is minimized/maximized (simply, a window's state);
    - get an url address typed in the browser.
    If any of these conditions is not met, I have to open the browser in a maximized view with a desired url address. I primarily wanted to do all this in Java, but it came to my mind that I should employ many techniques/technologies and combine them appropriately to complete the functionality. But, which ones? That's the problem. I just recalled Windows API, but I'm not sure if it is of any help... On another forum, some users suggested that I should consider JNI... At this time, I only know how to open a default browser (e.g. with use of the 'browse(URI uri)' method of the 'java.awt.Desktop' class) - that's too little to be proud of. Please give me some hints, maybe links to reasonable discussions, I would greatly appreciate any suggestions how to approach the problem.

    Crosspost! [http://www.java-forums.org/advanced-java/29583-how-check-whether-default-browser-opened-operating-system.html]

  • How to open a URL in the default browser via CC HTML Extension?

    Hi,
    I'm trying to open a link via the default browser in a HTML Extension for Photoshop CC built with Extension Builder 3.
    With the initial example the "/indext.html" it look like this:
    <li><button class="default" id="btn_PHXS" onClick="onClickButton('PHXS')" disabled="true">Run ps code</button></li>
    and I changed the code from "/ext.js" to:
    ...function onClickButton(ppid) {    var csInterface = new CSInterface();    csInterface.openURLInDefaultBrowser('http://www.adobe.com');}...
    This is what the "/lib/CSInterface-4.0.0.js" looks like:
    * Opens a page in the default system browser.
    * @param url   The URL of the page to open. Must use HTTP or HTTPS protocol.
    * @return One of these error codes:\n
    *      <ul>\n
    *          <li>NO_ERROR - 0</li>\n
    *          <li>ERR_UNKNOWN - 1</li>\n
    *          <li>ERR_INVALID_PARAMS - 2</li>\n
    *          <li>ERR_INVALID_URL - 201</li>\n
    *      </ul>\n
    CSInterface.prototype.openURLInDefaultBrowser = function(url)
        return cep.util.openURLInDefaultBrowser(url);
    Since "util" doesn't seem to be defined  I get the message:
    Uncaught TypeError: Cannot call method 'openURLInDefaultBrowser' of undefined
    Is the something missing?
    Thx,
    frankin

    Hi Franklin,
    Apologies for the delay but I have been trying to determine why this API is not been working. I have since discovered that, although this API is documented in the JS library, the behaviour has yet to be implemented into Photoshop CC. Offline I will try to determine why this API was included in the library when it was not ready but for the meantime, if you would like to open a browser, here is a workaround:
    Instead of using:
    //(new CSInterface).openURLInDefaultBrowser("http://www.adobe.com")
    // Use the createProcess API to open a browser. The following shows a workflow in Windows to open Internet Explorer.  
    var csInterface = new CSInterface();
    var rootDir = "/";
    var isWindows = window.navigator.platform.toLowerCase().indexOf("win") > -1;
    if (isWindows) {
                        rootDir = csInterface.getSystemPath(SystemPath.COMMON_FILES).substring(0, 3);
    var processPath = "/usr/bin/open";
      if (isWindows) {
        processPath = rootDir + "Windows/explorer.exe";
    var url = "http://www.adobe.com";
    window.cep.process.createProcess(processPath, url);
    Apologies for this inconvenience but we promise to keep you informed when openURLInDefaultBrowser API is fully supported.
    Kind regards,
    Lea

  • Bug report: on LabVIEW 2011 SP1 and Windows 8 'Open URL in default browser.vi'

    Dear colleagues,
    Here is a bug report.
    Culprit: 'Open URL in default browser.vi'.
    System: Windows 8, Professional. LabVIEW 2011 SP1.
    Abnormal behaviour and steps to reproduce:
    Above mentioned VI doesn't work when LabVIEW was started with administrator privilegies. And it works as expected when LabVIEW running in normal (non-administrator) mode. 
    Looking forward to see this fixed.
    Best regards,
    Igor Titov.
    CLD.
    =========================
    Igor Titov, CLA
    WebPager - put LabVIEW front panels into the web page
    Labicom.net

    Hi Igor,
    Unfortunately LabVIEW 2011 SP1 does not support Windows 8. I tested this behavior with LabVIEW 2012 SP1 on Windows 8 and everything worked correctly. 
    Regards,
    Jeff Peacock 
    Product Support Engineer | LabVIEW R&D | National Instruments 

  • Open URL in default browser

    Hi All,
    I'm very new to this (java(fx) programming) and the last days I'm trying to figure out how I can open the default browser when the user clicks the image (loaded from webpage) in the JFXPanel. This image comes from an openx (ads) server and holds a URL as destination link.
    So far all my attempts to accomplish this have failed and I'm lost in this.
    Currently when clicking the image, the destination webpage opens in in the same JFXpanel (ofcourse), but I would like to open this in the default browser.
    this is what I currently have for initiating the scene from swing
                ap = new AdsPanel();
                ap.init();
                JPanel ad = new JPanel();
                ad.add(AdsPanel.fxContainer);the class for loading the webpage:
        //@Override
        public void init()
            fxContainer = new JFXPanel();
            fxContainer.setPreferredSize(new Dimension(JFXPANEL_WIDTH_INT, JFXPANEL_HEIGHT_INT));
            // create JavaFX scene
            Platform.runLater(new Runnable()
                @Override
                public void run()
                    createScene();
    private void createScene()
            Platform.runLater(new Runnable()
                @Override
                public void run()
                    loadURL(FixedVars.SPONSORLINK);
                    WebView view = new WebView();
                    webEngine = view.getEngine();
                    view.setContextMenuEnabled(false);
                    Scene scene = new Scene(view);
                    fxContainer.setScene(scene);
            });Hope some can help me out.
    Thank you very much in advance.

    Just found my solution!! OPening the default browser in a separate thread. Please feel free to comment me, on the code (I do not earn my money as a developer)
    private void createScene()
            Platform.runLater(new Runnable()
                @Override
                public void run()
                    loadURL(FixedVars.SPONSORLINK);
                    WebView view = new WebView();
                    webEngine = view.getEngine();
                    view.setContextMenuEnabled(false);
                    webEngine.locationProperty().addListener(new ChangeListener<String>()
                        @Override
                        public void changed(ObservableValue<? extends String> observable, final String oldValue, final String newValue)
                                if ( !newValue.contains(FixedVars.SPONSORLINK) )
                                    System.out.println("newval =: " + FixedVars.SPONSORLINK);
                                    Platform.runLater(new Runnable()
                                        @Override
                                        public void run()
                                            loadURL(oldValue);
                                    // open the destination URl in the default browser
                                    // class will open a new thread
                                    BrowserOpener.main(newValue);
                    Scene scene = new Scene(view);
                    fxContainer.setScene(scene);
        }and the class opening the default browser:
    public abstract class BrowserOpener implements Runnable {
         * url string
        private static String uriString;
        public void open(String url) throws Exception{
            URI u = new URI(url);
            java.awt.Desktop.getDesktop().browse(u);
        public void run() {
            try
                open(uriString);
            catch ( Exception ex )
                Logger.getLogger(BrowserOpener.class.getName()).log(Level.SEVERE, null, ex);
        public static void main(String args) {
            (new Thread(new BrowserOpener() {})).start();
            uriString = args;
    }

  • I work with a web app that will not run on Firefox, so I changed my default browser back to IE but the URL link continues to open in Firefox. How can I get it to default to IE?

    After changing my default browser from Firefox back to IE, other URLs are defaulting to IE but I have one URL that continues to default to Firefox. This web app will only run in IE so the only way I can run it is to open IE first and then enter or select the URL. Is there a setting someplace that will change the default browser for this URL to be IE?

    You can make IE the default browser, that will reset some registry keys<br />
    Control Panel > Internet Options: Programs<br />
    Put a check in the box next to 'Internet Explorer should check to see whether it is the default browser'<br />
    Start IE and let IE make itself the default browser.
    Check the default settings in:<br />
    Control Panel > Add/Remove Programs > "Set Program Access And Defaults" (on the left)<br />
    Open: Custom (click arrow on the right)<br />
    Select "Internet Explorer" under "Choose a default Web Browser"<br />
    Click OK

  • Why do we use open URL in default browser function? What are the uses of it?

    Why do we use "open URL in default browser" function?  What are the uses of it?

    kdm7 wrote:
    Okay.
    So can we keep a web button to access the www.ni.com ? So that web site opens only when button pressed?
    P.S  I,m a newbie.
    Yes, you can also, e.g. include a help file or manual as html and open that in the browser.
    /Y
    LabVIEW 8.2 - 2014
    "Only dead fish swim downstream" - "My life for Kudos!" - "Dumb people repeat old mistakes - smart ones create new ones."
    G# - Free award winning reference based OOP for LV

  • How can I get specific URLs from outlook to open in firefox where IE is my default browser

    I require to open specific URLs from outlook to be opened in Firefox. However, IE will be my default browser.

    Try this tutorial ;)
    http://support.mozilla.com/en-US/kb/Remembering+passwords

  • 3.6.13 OS MAC 10.6.6 - cannot open url within Mail with Firefox as default browser

    new iMac (March '10) - no problem til last week - as above - when
    Firefox is my default browser cannot open url's form within Mail.
    OK when I change over to Safari - but going back to Firefox same issue.
    Firefox browser opens but the page does not load....
    any suggestions?

    I have the same issue. One interesting piece of info is if you quit FireFox (go to dock > right click on firefox icon > quit) Mail will then launch the link into FireFox properly. Somehow though users actions must cause it to fail again. My wife uses our iMac more than I do for email, so I haven't been able to re-create what she is doing to lose the Mail > Firefox functionality. Almost sounds like an OS X bug??

  • Can't open URLs in outlook 2010 email. Works OK when IE is default browser. URL opens properly when I paste it into FF.

    Running Win 7, Outlook 2010 and FF 3.6.15. I used to have no problem clicking URLs in Outlook messages, but now, when FF is default browser, I get message: "General Failure. The url was: "http://.....". An error occurred sending the command to the application." Link opens OK if I copy url to FF. Also works when IE is default browser.

    Every single time that I have to do an update on Firefox I then have to go back into the regedit and follow the directions again in order to prevent this error. The issue should be corrected by Mozilla on their next update. To be honest, it is kind of annoying!! This has been an issue for several months, and I am tired of having to fix their mistakes!''' MOZILLA!!! PLEASE FIX THIS ISSUE!!!'''
    I HAVE ATTACHED A SCREEN SHOT OF THE ERROR THAT I AM GETTING.

  • Firefox is my default browser in my local system, i am getting junk data when i open the .html type of files as attachment but there is no issue when i open as inline

    Hi,
    could please help me of the folloing issue
    i have set up the firefox is default browser in my local system.
    issue with only .html type files not with .doc .... etc.
    my application requirement is to view the attached document if set Content-Disposition as "attachement" then open the dialog box with open or save radio options then if i select the open option data getting as junk data not the actual data.
    if set Content-Disposition as "inline"' then file open in same accessing browser with proper data.
    Note
    i am using following piece of code in my application
    response.setHeader("Content-Disposition", "attachment;filename=\""
    + fileName + "\"");
    actual my case is :
    some where in my application i copy/paste the data from ms-word
    then it saved as .html file after that when i want to see the data, then click on the attachment it opens dialog box, here i am selecting open option then it opens in my default browser "firefox" with junk data .
    please observe the following junk data,

    Hi 20fox12, this is most likely an IE problem. Firefox has no effect on any other installed applications. Unfortunately I have no idea what to do about your issue. I'd suggest a forum that is more tuned towards Windows issues.

  • Make firefox handle URLs from other applications, when not the default browser

    I know there is a preference for this SOME WHERE because I saw it. Now I want to change it.
    I want to toggle whether clicking on a URL in some other app (like my email) will be handled by the Macintosh Default Browser (Safari) or by Firefox

    Only the default browser can handle links automatically.<br />
    That is handled by the OS and can't be affected otherwise.
    If you do not want to change to default browser to Firefox then you need to drag the link in a Firefox window or otherwise open the link in the preferred browser.

Maybe you are looking for

  • SQL 2014 Exp Wont Install Win 8.1

    Hello All, Im really struggling to install SQL 2014 express on my windows 8.1  SL pc. x64 i installed SQL 2008 first but when i tried to install the studio management, it refused to work. so i redownloaded the latest setups. ive tried both 32bit and

  • NIO: issues with the IO part

    I've been working on a multi client/ server system, and I had success with traditional networking using Sockets, streams and Threads to handle each connection. In an attemp to make my srver more efficient using asynchronous communication (which I am

  • Dvd feed not working

    My macbook pro (15" mid 2012) has suddenly stopped feeding a DVD into the drive.  I have a 2.3GH intel core i7 running on OS X 10.9.4. I have already tried restarting my macbook but no luck.  Any suggestions would be hugely appreciated.  Thank you.

  • I can't acess the movies I just rented on my iPad

    I downloaded the movies from iTunes but can't find them anywhere.

  • How to Automatically Logout Users

    We recently created user accounts to enable parental controls for our teens. Very often, someone in the house will have used the mac, but forgets to logout from their account. Since there are different restrictions on different accounts, I would like