our
@EXPORT
=
qw(get_default_browser)
;
our
$VERSION
=
'1.03'
;
sub
get_default_browser
{
my
$strBrowser
= 0;
my
$strSubBrowser
= 0;
my
$strFallbackBrowser
= 0;
my
$boolIs64Bit
= 0;
if
(
$ENV
{
'PROGRAMW6432'
} =~ m/\w/)
{
$boolIs64Bit
= 1;
}
if
((
$boolIs64Bit
) && (-e (
$ENV
{
'SYSTEMDRIVE'
} .
'\\Program Files (x86)\\Internet Explorer\\iexplore.exe'
)))
{
$strFallbackBrowser
=
$ENV
{
'SYSTEMDRIVE'
} .
'\\Program Files (x86)\\Internet Explorer\\iexplore.exe'
;
}
elsif
(-e (
$ENV
{
'SYSTEMDRIVE'
} .
'\\Program Files\\Internet Explorer\\iexplore.exe'
))
{
$strFallbackBrowser
=
$ENV
{
'SYSTEMDRIVE'
} .
'\\Program Files\\Internet Explorer\\iexplore.exe'
;
}
if
(!
$strFallbackBrowser
)
{
$strFallbackBrowser
=
'iexplore.exe'
;
}
my
@strWinVer
= Win32::GetOSVersion;
my
$strMajorWinBuild
=
$strWinVer
[1];
if
(
$strMajorWinBuild
>= 10)
{
my
$RegHash
= new Win32::TieRegistry(
'HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\Shell\\Associations\\UrlAssociations\\http\\UserChoice'
, {
Access
=> KEY_READ(),
Delimiter
=>
'\\'
});
if
(
$RegHash
)
{
my
$strBrowser
=
$RegHash
->GetValue(
'ProgId'
);
if
(
$strBrowser
)
{
my
$sub_regkey
= new Win32::TieRegistry(
'HKEY_CLASSES_ROOT\\'
.
$strBrowser
.
'\\shell\\open\\command'
, {
Access
=> KEY_READ(),
Delimiter
=>
'\\'
});
if
(
$sub_regkey
)
{
$strSubBrowser
=
$sub_regkey
->GetValue(
''
);
}
}
}
if
(
$strSubBrowser
=~ m/^
"([^"
]{1,})"/)
{
$strSubBrowser
= $1;
}
}
elsif
(
$strMajorWinBuild
> 5)
{
my
$regkey
= new Win32::TieRegistry(
'HKEY_CURRENT_USER\\Software\\Clients\\StartMenuInternet'
, {
Access
=> KEY_READ(),
Delimiter
=>
'\\'
});
if
(
$regkey
)
{
$strBrowser
=
$regkey
->GetValue(
''
);
if
(
$strBrowser
)
{
my
$regpath_str
=
'HKEY_LOCAL_MACHINE\\Software\\Clients\\StartMenuInternet\\'
.
$strBrowser
.
'\\shell\\open\\command'
;
if
(
$boolIs64Bit
)
{
$regpath_str
=
'HKEY_LOCAL_MACHINE\\Software\\Wow6432Node\\Clients\\StartMenuInternet\\'
.
$strBrowser
.
'\\shell\\open\\command'
;
}
my
$sub_regkey
= new Win32::TieRegistry(
$regpath_str
, {
Access
=> KEY_READ(),
Delimiter
=>
'\\'
});
if
(
$sub_regkey
)
{
$strSubBrowser
=
$sub_regkey
->GetValue(
''
);
}
}
}
$strSubBrowser
=~ s/["']//g;
}
else
{
my
$regkey
= new Win32::TieRegistry(
'HKEY_CLASSES_ROOT\\HTTP\\shell\\open\\command'
, {
Access
=> KEY_READ(),
Delimiter
=>
'\\'
});
if
(
$regkey
)
{
$strSubBrowser
=
$regkey
->GetValue(
''
);
$strSubBrowser
=~ s/(\.exe).{1,}$/$1/i;
$strSubBrowser
=~ s/["']//g;
}
}
if
((! (
length
(
$strSubBrowser
))) || (!-e
$strSubBrowser
))
{
$strSubBrowser
=
$strFallbackBrowser
;
}
return
(
$strSubBrowser
);
}