pramodkh has asked for the wisdom of the Perl Monks concerning the following question:

Hi All
I recently joined this forum.
I have a question. I am writting a script to get the details of a windows Registry Key.
This is what i have tried so far.
my $Register = "Path of the Registry"; my ($RegType, $RegValue, $RegKey, $value,$hkey); my %values; $HKEY_LOCAL_MACHINE->Open($Register, $hkey); if (defined $hkey ){ $hkey->GetValues(\%values); foreach my $key (keys(%values)) { $RegType = $values{$key}->[1]; $RegValue = $values{$key}->[2]; $RegKey = $values{$key}->[0]; print "\nREG KEY = $RegKey"; print "\nREG VALUE = $RegValue"; print "\nTYPE = $RegType : "; print "\n\n" } $hkey->Close(); }else { print "\n $hkey NOT DEFINED for $Register..."; }
Please tell me if I am on the right track.
None of my appraoches are working. Please advise.
Thanks!

Replies are listed 'Best First'.
Re: Working with Windows Registry in PERL
by marto (Cardinal) on Jun 11, 2008 at 09:30 UTC
    Firstly,

    Welcome to the Monastery, please read the PerlMonks FAQ and How do I post a question effectively? if you have not already done so. Secondly, are you using a module here? You tell us that none of your approaches are working, are you receiving errors? This does not look like a complete script. Have you seen the Win32::TieRegistry module?

    Martin
Re: Working with Windows Registry in PERL
by Anonymous Monk on Jun 11, 2008 at 09:24 UTC
    You're on the right track, but you don't explain what module you are using, or how your approaches aren't working (what do you expect to happen, what actually happens -- How (not) to ask a question)

    If you're using Win32::Registry (just guessing here), its documentation states obsolete, use Win32::TieRegistry

      Yes I am using Win32::Registry module.
      Let me check Win32::TieRegistry

      Thanks.
Re: Working with Windows Registry in PERL
by andreas1234567 (Vicar) on Jun 11, 2008 at 09:30 UTC
    Have you tried any of the suitable modules on CPAN?
    --
    No matter how great and destructive your problems may seem now, remember, you've probably only seen the tip of them. [1]
      Using Win32::TieRegistry module I tried this :
      use Win32::TieRegistry( Delimiter=>"/", ArrayValues=>0 ); $RegHash= $Registry->{"HKEY_LOCAL_MACHINE/SYSTEM/CURRENTCONTROLSET +/SERVICES/MSSQL\$SQLEXPRESS/"} #$tips= $Registry->{"HKEY_LOCAL_MACHINE/SOFTWARE/PMS/"} or die "Can't find the Windows Registry: $^E\n"; foreach( keys %$RegHash ) { #print "$_: ", $RegHash->{$_}, "\n"; if ( defined $_ ) { print "$_ is defined...\n"; } }
      But this will give only if subkey exists...how to get the details of a subkey? Each subkey has Name/Type and Data defined. How do i get these details?
      Basically i want to compare the actual registry key values with the expected( which is maintained in a file).
      Thanks.