in reply to How to start default browser on Windows?
sub open_browser {
my ($obj, $url) = @_;
#
# open the registry to find the path to the default browser
#
my $cmdkey = $reg{ 'HKEY_CLASSES_ROOT/' .
$reg{'HKEY_CLASSES_ROOT/.htm//'} .
'/shell/open/command'};
my $sysstr = $cmdkey->{'/'};
#
# replace the argument PH with our URL
#
$url=~tr/\\/\//;
$url = "file://C:$url"
unless ($url=~/^(http|file):\/\//);
$sysstr=~s/\-nohome//;
if ($sysstr=~/%1/) {
$sysstr =~ s!%1!$url!;
}
else {
$sysstr .= " $url";
}
my $exe = $sysstr;
#
# in case we get a fancy pathname, strip the
# quotes
#
if ($sysstr=~/^"/) {
$exe=~s/^"(^"+)"\s+.+$/$1/;
}
else {
$exe=~s/^(\S+)\s+.+$/$1/;
}
# start the browser...
my $browser;
Win32::Process::Create($browser,
$exe,
$sysstr,
0,
NORMAL_PRIORITY_CLASS,
'.'
) or die Win32::FormatMessage(Win32::GetLastError());
return 1;
}
|
|---|