Thread: Getting Default Browser and Running It

  1. #1
    Registered User
    Join Date
    Sep 2004
    Posts
    124

    Getting Default Browser and Running It

    I've got this problem in that getting the default browser, then opening it by way of SheffExecute() passing the name of an HTML file as a parameter doesn't always work.

    I look in the HKEY_CLASSES_ROOT\http\shell\open\command key to get the default browser. I then strip out all unwanted crud such as quotes, -nohome parameters and the like thus leaving me with just the absolute path to the browser. Sample strings of what I end up with are as follows:

    C:\PROGRA~1\MOZILL~1\FIREFOX.EXE
    C:\PROGRA~1\MOZILLA.ORG\MOZILLA\MOZILLA.EXE
    C:\Program Files\Internet Explorer\iexplore.exe

    I get a variety of responses, it seems, depending on the system which is running the program, although I cannot get it to fail on my own system:

    1. The browser is not opened at all. This has happened with the first 2 browsers mentioned, but Firefox works OK on my system (not working)
    2. The HTML page replaces the most recent instance of the browser (not the desired effect)
    3. A new browser instance is created, containing the HTML page passed as the parameter.

    It seems as though the version of Windows alters the behaviour as well as the browser. What I'm wondering is this:

    1. Does the fact that sometimes you get the MS-DOS pathnames (i.e. restricted to 8 characters, thus PROGRA~1 etc) make a difference when passed to ShellExecute()? If so, is there a way to translate these to their full counterparts?

    2. Is there any reason why code such as the following:

    Code:
    ShellExecute(hwnd, "open", DefBrowser, OutFileName, NULL, SW_SHOW);
    (where DefBrowser contains a string pointing to the default browser such as at the start of this post and OutFileName is the complete path to an HTML file)

    should open a new browser window on some systems, 'take over' a previous session on others, and not do anything at all on others?

    Any ideas? Thanks in advance!

  2. #2
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,268
    Why not just do:
    Code:
    ShellExecute( NULL, "open", "http://www.someurl.com", NULL, NULL, SW_SHOWNORMAL );

  3. #3
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    Because if you already have a browser window open on another site, that code will cause that instance to be taken over by http://www.someurl.com.

    That's an effect I'm specifically NOT wanting to achieve - I need a new browser window.

  4. #4
    erstwhile
    Join Date
    Jan 2002
    Posts
    2,227
    I don't think the format of the path should make any difference to ShellExecute but if you want to convert between the two then GetShortPathName and GetLongPathName are the API functions of interest.

    Have you tried using CreateProcess?
    CProgramming FAQ
    Caution: this person may be a carrier of the misinformation virus.

  5. #5
    Registered User
    Join Date
    Sep 2004
    Posts
    124
    I did consider using CreateProcess, but it seemed such a lot of faffing aound just to kick off a new instance of another program.

    As for the path name issue, I noticed that the tester seemed to get the browser opening up when the full path was available, but not otherwise.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Editing variables while running a flash program.
    By two31d in forum Tech Board
    Replies: 2
    Last Post: 02-28-2006, 01:27 PM
  2. What browser do you use?
    By joshdick in forum Tech Board
    Replies: 38
    Last Post: 01-07-2003, 08:14 AM