Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
###################################################################### +###### ### Title: regtool.pl ### Description: Win32 Registry key listing ###################################################################### +###### use Win32::TieRegistry; use Getopt::Long; use Pod::Usage; use strict; use vars qw($pound $key $help $man); my %regtypes = (1=>'REG_SZ', 2=> 'REG_EXPAND_SZ', 3=>'REG_BINARY', 4=> +'REG_DWORD', 7=>'REG_MULTI_SZ'); sub ListKey { #$RRef is a TieRegistry ref my $RRef = shift; for my $key ($RRef->SubKeyNames) { print "[$key]\n"; } for my $key ($RRef->ValueNames) { my ($ValueData,$ValueType)= $RRef->GetValue( $key ); $key = "(Default)" unless $key; if ($regtypes{$ValueType} eq 'REG_BINARY') { $ValueData = unpack ("H*", $ValueData); $ValueData =~ s/([0-9a-f]{2})/$1 /gi; } elsif ($regtypes{$ValueType} eq 'REG_MULTI_SZ') { $ValueData= join "\n\t",@$ValueData; } print "$key ($regtypes{$ValueType})\n\t$ValueData\n"; } printf ("%0d keys, %0d values", scalar $RRef->SubKeyNames, scalar +$RRef->ValueNames); } sub ExtendedPath { my $rpath=shift; $$rpath =~ s|/?[^/]*/\.\.||g; } GetOptions('help|?' => \$help, man => \$man); pod2usage(1) if $help; pod2usage(-exitstatus => 0, -verbose => 2) if $man; #First of all, the registry delimiter (to avoid backslashing) $pound= $Registry->Delimiter("/"); #Without these two lines, we can't read REG_MULTI_SZ or REG_EXPAND_SZ +keys $Registry->FixSzNulls(1); $Registry->SplitMultis(1); #If there is a parameter, we will try to use it as "current key" my $subkey = shift; eval { $Registry->Open($subkey); }; #If there is an error, current key is the root of the registry $subkey ="" if ($@); for (;;) { #Interactive Mode #First, we print the prompt (path and $) print "\n[/$subkey]\$ "; #Read the command my $command = <STDIN>; chomp $command; my ($commandname, @arguments) = split /\s+/, $command; my $arguments = join " ",@arguments; if (lc $commandname eq 'quit' or lc $commandname eq 'exit') { last; } elsif ( lc $commandname eq 'dir' or lc $commandname eq 'ls') { #List command #If there is a paremeter, could be a key that we want to list $arguments = $subkey unless $arguments; ExtendedPath(\$arguments); #If no, we'll list the current key eval { $key = $Registry->Open($arguments); }; if ($@ or ref $key ne 'Win32::TieRegistry') { #If error, $arguments maybe a relative path eval { my $path = "$subkey/$arguments"; ExtendedPath(\$path); $key = $Registry->Open($path); }; if ($@ or ref $key ne 'Win32::TieRegistry') { print "Error: $arguments doesn't exist\n"; next; } } ListKey($key); } elsif (lc $commandname eq 'cd') { #"Change Directory" command unless ($arguments) { #If not parameter, "current key" is shown print "$subkey\n"; } #If there is a paremeter, we try to open this registry key eval { $key = $Registry->Open($arguments); }; if ($@ or ref $key ne 'Win32::TieRegistry') { #If error, may be a "relative path" to the current key eval { my $path = "$subkey/$arguments"; ExtendedPath(\$path); $key = $Registry->Open($path); }; if ($@ or ref $key ne 'Win32::TieRegistry') { print "Error: $arguments doesn't exist\n"; next; } else { $arguments="$subkey/$arguments"; ExtendedPath(\$arguments); } } $subkey = $arguments; } else { print "$commandname is not a valid command.\n"; } } =pod =head1 NAME regtool.pl - Win32 Registry list keys =head1 SYNOPSIS regtool.pl is a simple utility to list win32 registry keys. =head2 regtool.pl sintax regtool.pl regtool.pl --help, regtool -h regtool.pl --man, regtool -m =head1 OPTIONS =over 4 =item cd key Change current key =item dir [key] (or ls [key]) List key. If key is not provided, actual registry key is listed =item quit (or exit) Quit regtool.pl =back =head1 DESCRIPTION This utility allows to list keys in the Win32 Registry. When you execute regtool.pl you see a console like this: [/]$ You can move arround the keys of the registry like if you where in + a directory tree. When you use cd (change directory) or ls (list directory) it is po +ssible to use '.' and '..' to refer the "actual registry key" and the "previous regi +stry key" [/LMachine]$ cd SOFTWARE [/LMachine/SOFTWARE]$ cd ../SYSTEM [/LMachine/SYSTEM]$ To list a key, you can use 'ls' or dir command [/LMachine/Software]$ ls .. [HARDWARE] [SAM] [SECURITY] [SOFTWARE] [SYSTEM] 5 keys, 0 values [/LMachine/Software/Perl]$ ls (Default) (REG_SZ) D:\Perl\ BinDir (REG_SZ) D:\Perl\bin\perl.exe regtool.pl can list: REG_SZ REG_EXPAND_SZ REG_BINARY REG_DWORD REG_MULTI_SZ keys =head1 AUTHOR Fermin Palacios (hopes at perlmonks.org) larioja.pm@fitipaldis.com =cut

In reply to Regtool by hopes

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (9)
As of 2024-04-23 10:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found