back forward index

Registry scripts for 95 and NT


  1. The best example is of course The perl install script itself
  2. What the script does ,or read what you've written
  3. Recurse through the registry

 


Clip from the install script

&log( "Copying over perl and utility scripts to $bindir\n" );

`copy ntt\\perl.exe $bindir`;
`copy ntt\\perlglob.exe $bindir`;
`copy ntt\\cmd32.exe $bindir`;
`copy pl2bat.bat $bindir`;


NTRegCreateKeyEx( &HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Resource Kit\PERL5',
    &NULL, 'NT Perl 5', &REG_OPTION_NON_VOLATILE, &KEY_ALL_ACCESS, &NULL,
    $hkey, $disposition ) ?
    &log( "Added key for Perl 5 to NT Registry Database..\n" ):
    &gripe( "Couldn't add key for Perl 5 to NT Registry Database!!\n" );

if ( $disposition  == &REG_OPENED_EXISTING_KEY ) {
    &gripe( "Key exists already, modifying existing key...\n" );
}

NTRegSetValueEx( $hkey, 'BIN', &NULL, &REG_SZ, "$bindir" ) ?
    &log( "Adding $bindir to script path information\n" ):
    &gripe( "Couldn't add script path to registry!!\n" );

NTRegSetValueEx( $hkey, 'PRIVLIB', &NULL, &REG_SZ, "$libdir" ) ?
    &log( "Adding $libdir to library include path information\n" ):
    &gripe( "Couldn't add library path to registry!!\n" );

NTRegSetValueEx( $hkey, 'HTML-DOCS', &NULL, &REG_SZ, "$docdir" ) ?
    &log( "Adding $docdir to documentation directory\n" ) :
    &gripe( "Couldn't add documentation directory to registry!!\n" );

NTRegCloseKey( $hkey );

Back to Top

Perl Info from the registry

use Win32::Registry;
#use lib::nt.ph;
# Query the registry for path values:
local($hkey);
local($myhash);

$HKEY_LOCAL_MACHINE->Open('SOFTWARE', $hkey) || die $!;
$hkey->Open('Microsoft', $hkey) || die $!;
$hkey->Open('Resource Kit', $hkey) || die $!;
$hkey->Open('PERL5', $hkey) || die $!;
$hkey->GetValues($myhash) || die $!;
print "perl bin directory: $myhash->{'BIN'}[2]\n";
print "perl lib directory: $myhash->{'PRIVLIB'}[2]\n";
print "perl doc directory: $myhash->{'HTML-DOCS'}[2]\n";

Back to Top

Recurse the registry

use Win32::Registry;

print("HKEY_LOCAL_MACHINE ROOT\n");
local($hkey);
$HKEY_LOCAL_MACHINE->Open($object, $hkey) || die"Can't open Root $!";
&SearchKey($hkey, '');


sub SearchKey
{
 local($Instance, $object) = @_;
 local($hkey);
 local (@savedkeys,$Key);
 $Instance->Open($object, $hkey) || die"can t open $object $!";
 $keys = [];
 $hkey->GetKeys($keys)||die "Can't get keys for $object $!";
 @savedkeys=@$keys;
 foreach (@savedkeys)
 {
  $Key = $_;
  last if (!defined $Key );
 # print(">@$keys<\n");
  if (defined $Key )
  {
   $Subkey .= "$_\\";
   print("Parameter   Key>$Key<  \n");
   &SearchKey($hkey,$Key);
   print("After call  Key>$Key<  \n");
   sleep(3); # only needed if you want to see what's coming
 }
 $hkey->Close;
};


Back to Top


Copyright © Robin S. Chatterjee. All rights reserved.

back forward index

This page hosted by Get your own Free Home Page