Created
March 12, 2011 13:18
-
-
Save zippy1981/867228 to your computer and use it in GitHub Desktop.
demonstrates how to get the path of 7zip from the registry
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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