|
From: Thomas, T. B <tim...@lm...> - 2001-01-15 16:16:18
|
Sean -=20
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.=20
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)=3D$command=3D~/^(.*)\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=3D"C:\PROGRA~1\Plus!\MICROS~1\iexplore.exe"
.htm=3D"C:\PROGRA~1\Plus!\MICROS~1\iexplore.exe"
.txt=3D"C:\Program Files\Windows NT\Accessories\WORDPAD.EXE"
.pl=3DC:\Perl\bin\Perl.exe
.doc=3D"C:\Program Files\Microsoft Office\Office\winword.exe"
.xls=3D"C:\Program Files\Microsoft Office\Office\excel.exe"
.ppt=3D"C:\Program Files\Microsoft Office\Office\PowerPnt.exe"
.log=3D"C:\Program Files\Windows NT\Accessories\WORDPAD.EXE"
.url=3Drundll32.exe
.jpg=3DC:\PROGRA~1\PAINTS~1\psp.exe
.gif=3DC:\PROGRA~1\PAINTS~1\psp.exe
.avi=3D"C:\Program Files\Windows Media Player\mplayer2.exe"
.wav=3D"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)=3D@_;
$prog=3DgetProgram($item);
print "$item=3D$prog\n";
}=09
sub getProgram
{
if (my $ext =3D $_[0])
{
if (my $typeName =3D $Registry->{"HKEY_CLASSES_ROOT\\$ext\\\\"})
{
if (my $command =3D =
$Registry->{"HKEY_CLASSES_ROOT\\$typeName\\shell\\open\\command\\\\"})
{
my ($cmd);
#print "\tcommand=3D$command\n";
if ($command=3D~/^".*"\s+.*$/)
{
($cmd)=3D$command=3D~/^(".*")\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 =B7 Denver Data Center
303-430-2281
mailto:tim...@lm...
------------------------------------------------------------------------=
-------------------------
-----Original Message-----
From: Sean Healy [mailto:jal...@ho...]
Sent: Saturday, January 13, 2001 9:13 AM
To: per...@li...
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 =3D $_[0])
{
if (my $typeName =3D $Registry->{"HKEY_CLASSES_ROOT\\$ext\\\\"})
{
if (my $command =3D=20
$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=20
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=20
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=20
sure the file type has a command associated with it). I have not =
tested=20
case sensitivity (I know Windows is not case-sensitive as far as file =
names=20
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
Per...@li...
http://lists.sourceforge.net/lists/listinfo/perl-win32-gui-users
|