http://qs321.pair.com?node_id=9724

httptech has asked for the wisdom of the Perl Monks concerning the following question:

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?