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

The following is a modified version of a Java function I borrowed from one of the Javaworld tips to fire up the default browser at a particular URL in Windows:

$url = ...;
$cmd = "rundll32 url.dll,FileProtocolHandler $url";
unless ( fork ) { exec $cmd; }
I'm not on a Windows box now, so I don't know the ramifications of using Perl's fork() under Win32, and I haven't tested this code. Of course, there should be a bit of error checking here and there, but you get the general idea. The tech tips can be found off Javaworld at http://www.javaworld.com/ - just search for 'browser' on the tips page (they also have code for kicking off a browser in Unix).

Replies are listed 'Best First'.
Re^2: rundll32 is the right answer!
by rduke15 (Beadle) on Apr 10, 2005 at 16:47 UTC
    I came across this thread several years after the original post, and would like to confirm that this rundll32 solution works perfectly. It is also much better than the Win32::Shell solution, because it doesn't require a module install.

    Before finding the answer here, I had tried extracting the http handler program from the registry and calling it directly. That seemed fine until I tried to switch my default browser to Internet Explorer. The exe lives in "C:\Program Files\Internet Explorer\iexplore.exe" so exec() cannot be used because of the spaces in the path. system() worked, but the script doesn't return until the Explorer window is closed.

    I have now

    my $url = $baseurl . join("&", map {"$_=$params{$_}"} keys %params); my $cmd = qq{rundll32 url.dll,FileProtocolHandler "$url"}; exec $cmd;
    which works reliably.

    The next question will be how to achieve the same thing on Mac and Linux to have a multi-platform script, but that will be in another thread.

RE: Re:
by Anonymous Monk on Apr 30, 2000 at 16:26 UTC
    Sorry I can't be more technical here but I just don't have the technical details to hand.

    There is a Windows API function called ShellExecute which I think is what you are looking for. Look in the Win32 modules, and you should find more details. This should avoid the problem that you mention about the console window.

    As for the delay, maybe the console approach is slower, I don't know. I've done this through VB (with the API function) and it takes just as long as Netscape or IE would normally take to open up.

    Hope this helps