I want to do something very simple; launch the default browser in Win32 to go to a specified URL.

I've tried all the methods below; however, none seems to be a perfect solution.

For instance, I can use the easiest method, which is simply: system("start http://www.perlmonks.org/") but that opens a console window, and this is a GUI app, so that's an undesirable result. Plus, there is a delay of at least 10-15 seconds in launching Netscape. I'm not sure if there would be the same delay with IE or another browser, but it seems to take forever. Maybe this is a bug in Win32 but I can't just accept this solution.

I can use Win32:Process to avoid the console window opening, but the delay is still there. Note that using the "start" command from the MS-DOS window does not have a delay; it's only when I call it from perl.

I can get rid of the delay by calling the browser executable directly. To do that I use Win32::Registry to get the path to the browser:

use Win32::Process; use Win32::Registry; my $browsekey; my %vals; $main::HKEY_CLASSES_ROOT->Open('HTTP\shell\open\command', $browsekey) +|| die "Open f]ailed: $!"; $browsekey->GetValues(\%vals); my $default_browser = $vals{''}[2]; $default_browser =~ s/\.exe\s*(.*)/\.EXE/i; my $browser; Win32::Process::Create($browser, $default_browser, "$default_browser "http://www.perlmonks.org", 0, NORMAL_PRIORITY_CLASS, ".") || return 0;
This works on my system, but when I sent this to a friend it did not work on hers. I didn't really like this method anyway, there has to be an easier way.

So, I used the Win32:OLE example from Learning Perl on Win32:

use Win32::OLE; my $browser = CreateObject OLE "InternetExplorer.Application.1" || r +eturn 0; $browser->{'Visible'} = 1; $browser->Navigate("http://www.perlmonks.org/");
This works fine, except I'm now forcing the user to use IE instead of Netscape. And it's possible (not likely I realize) that they don't even have IE. So what happens then?

So, is there a generic way to call the default browser on Win32 that is guaranteed to work properly on any normal system?


In reply to How do I launch my browser in Win32 to go to a specified URL? by httptech

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.