Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Windows Registry Reads

Status
Not open for further replies.

DANZIG

Technical User
Mar 8, 2001
142
US
Hello All, I have a question about reading keys from the registry. The following code will read all subkeys below a defined key.


use Win32::Registry;
my $Register = "Software\\Microsoft";
my ($hkey, @key_list, $key);

$HKEY_LOCAL_MACHINE->Open($Register,$hkey)|| die $!;
$hkey->GetKeys(\@key_list);
print "$Register keys\n";
foreach $key (@key_list)
{
print "$key\n";
}
$hkey->Close();
$next = <STDIN>;


I would like to read a single specific key value and was wondering the best way to go about it. In kixtart I could use a 1 line statement to do this. If somebody wouldn't mind posting an example on the best way to read a single registry key value I would appreciate it.

Thanks in advance. =)
 
Have a look at Win32::TieRegistry, it lets you do things like this:
[tt]
use Win32::TieRegistry( Delimiter=>&quot;#&quot;, ArrayValues=>0 );
$pound= $Registry->Delimiter(&quot;/&quot;);
$diskKey= $Registry->{&quot;LMachine/System/Disk/&quot;}
or die &quot;Can't read LMachine/System/Disk key: $^E\n&quot;;
$data= $diskKey->{&quot;/Information&quot;}
or die &quot;Can't read LMachine/System/Disk//Information value: $^E\n&quot;;
$remoteKey= $Registry->{&quot;//ServerA/LMachine/System/&quot;}
or die &quot;Can't read //ServerA/LMachine/System/ key: $^E\n&quot;;
$remoteData= $remoteKey->{&quot;Disk//Information&quot;}
or die &quot;Can't read ServerA's System/Disk//Information value: $^E\n&quot;;
foreach $entry ( keys(%$diskKey) ) {
...
}
foreach $subKey ( $diskKey->SubKeyNames ) {
...
}
$diskKey->AllowSave( 1 );
$diskKey->RegSaveKey( &quot;C:/TEMP/DiskReg&quot;, [] );
[/tt]
Mike
michael.j.lacey@ntlworld.com
Email welcome if you're in a hurry or something -- but post in tek-tips as well please, and I will post my reply here as well.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top