Skip to content

Instantly share code, notes, and snippets.

@zippy1981
Created March 12, 2011 13:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zippy1981/867228 to your computer and use it in GitHub Desktop.
Save zippy1981/867228 to your computer and use it in GitHub Desktop.
demonstrates how to get the path of 7zip from the registry
#!/usr/bin/perl
use strict;
use DateTime;
my $dt = DateTime->now();
# We can't call it $7zip because variable names can't begin with a number.
#my $lzexe;
my $lzexe = get7Zip();
my $output = `"$lzexe"`;
my $logFile = 'commit_hook-' . $dt->ymd( '-' ) . '.log';
open(LOGFILE, ">>$logFile");
print LOGFILE $output;
close(LOGFILE);
# begin function definitions
sub get7Zip {
# This is a read/write registry module. With great power comes great responsibility.
my $Registry;
use Win32::TieRegistry (TiedHash => '%RegHash', TiedRef => \$Registry, Delimiter => "/");
# We can't call it $7zip
my $lzexe;
$lzexe = $Registry->{"LMachine/Software/"}
or die 'Can\'t read HKEY_LOCAL_MACHINE\Software';
$lzexe = $lzexe->{"7-Zip"}
or die 'Can\'t read HKEY_LOCAL_MACHINE\Software\7-Zip';
$lzexe = $lzexe->GetValue("Path") . '7z.exe'
or die 'Can\'t read value "Path" of HKEY_LOCAL_MACHINE\Software\7-Zip';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment