Sean -
Hey - that's pretty cool. I hadn't thought of taking that angle. I
noticed a problem or two with your code. The main one was that if your
association is pointing to something like "C:\Program Files\Windows
NT\Accessories\WORDPAD.EXE", it doesn't like it because of the space in
"Program Files". So I modified your code a little. I also put in some debugging
stuff to make it easier to see what's going on. Below is the output on a bunch
of different associations, all are coming out ok.
I am not sure I like your use of split on getting everything up to the first
space, but I couldn't figure out how to get everything up to the first space
using a regular expression. If you do something like
($cmd)=$command=~/^(.*)\s/; it gives you everything up to the last space, which
is annoying, I am sure there is a way around it.
Let me know your thoughts on it.
Also- How is Win32::TieRegistry different from Win32::Registry?
Tim
.html="C:\PROGRA~1\Plus!\MICROS~1\iexplore.exe"
.htm="C:\PROGRA~1\Plus!\MICROS~1\iexplore.exe"
.txt="C:\Program Files\Windows NT\Accessories\WORDPAD.EXE"
.pl=C:\Perl\bin\Perl.exe
.doc="C:\Program Files\Microsoft Office\Office\winword.exe"
.xls="C:\Program Files\Microsoft Office\Office\excel.exe"
.ppt="C:\Program Files\Microsoft Office\Office\PowerPnt.exe"
.log="C:\Program Files\Windows NT\Accessories\WORDPAD.EXE"
.url=rundll32.exe
.jpg=C:\PROGRA~1\PAINTS~1\psp.exe
.gif=C:\PROGRA~1\PAINTS~1\psp.exe
.avi="C:\Program Files\Windows Media Player\mplayer2.exe"
.wav="C:\Program Files\Netscape\Communicator\Winamp\winamp.exe"
Here's the code:
use Win32::TieRegistry;
check(".html");
check(".htm");
check(".txt");
check(".pl");
check(".doc");
check(".xls");
check(".ppt");
check(".log");
check(".url");
check(".jpg");
check(".gif");
check(".avi");
check(".wav");
sub check
{
($item)[EMAIL PROTECTED];
$prog=getProgram($item);
print "$item=$prog\n";
}
sub getProgram
{
if (my $ext = $_[0])
{
if (my $typeName = $Registry->{"HKEY_CLASSES_ROOT\\$ext\\\\"})
{
if (my $command =
$Registry->{"HKEY_CLASSES_ROOT\\$typeName\\shell\\open\\command\\\\"})
{
my ($cmd);
#print "\tcommand=$command\n";
if ($command=~/^".*"\s+.*$/)
{
($cmd)=$command=~/^(".*")\s+.*$/;
return $cmd;
}
else
{
split(/ /, $command);
return $_[0];
}
}
else { return 0; }
}
else { return 0; }
}
else { return 0; }
}
-------------------------------------------------------------------------------------------------
Tim Thomas
Unix Systems Administrator
Lockheed Martin EIS ยท Denver Data Center
303-430-2281
mailto:[EMAIL PROTECTED]
-------------------------------------------------------------------------------------------------
-----Original Message-----
From: Sean Healy [mailto:[EMAIL PROTECTED]
Sent: Saturday, January 13, 2001 9:13 AM
To: [email protected]
Subject: [perl-win32-gui-users] Getting the browser
Due to a message earlier this week, I was thinking about the problem of
getting a browser preference from the user's registry, so I wrote this:
use Win32::TieRegistry;
sub getProgram
{
if (my $ext = $_[0])
{
if (my $typeName = $Registry->{"HKEY_CLASSES_ROOT\\$ext\\\\"})
{
if (my $command =
$Registry->{"HKEY_CLASSES_ROOT\\$typeName\\shell\\open\\command\\\\"})
{
split(/ /, $command);
return $_[0];
}
else { return 0; }
}
else { return 0; }
}
else { return 0; }
}
You pass in the extension and this returns the path to the associated
program. The extension must include the dot (i.e, pass in '.html', not
'html').
This works on my machine, and you're welcome to use it (or modify it to make
it work on your system). It does some basic error checking (makes sure you
pass in an extension, makes sure the extension exists in the registry, makes
sure the file type has a command associated with it). I have not tested
case sensitivity (I know Windows is not case-sensitive as far as file names
go, but I don't know if the same applies to the registry).
I'd be glad to hear any feedback.
_________________________________________________________________
Get your FREE download of MSN Explorer at http://explorer.msn.com
_______________________________________________
Perl-Win32-GUI-Users mailing list
[email protected]
http://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users