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


Reply via email to