ashah21 has asked for the wisdom of the Perl Monks concerning the following question:
In the code below, if the first sub key SOFTWARE\\ActiveState\\ActivePerl does not exist then it fails to get the second key as well even if the second key exists. It works fine only if both keys exist. Please help.
#!/usr/bin/env perl -w use strict; use Win32API::Registry 0.21 qw( :ALL ); &main; sub getRegistryKeys { my ($hKey,$sKey,$sValue) = @_; my ($type, $data, $error, $key); RegOpenKeyEx( $hKey, $sKey, 0, KEY_READ, $key) or warn "Can't ope +n $hKey\\$sKey: ", regLastError(),"\n"; $error = regLastError(); print "\nError after open: $error"; return "error" if ($error ne ""); RegQueryValueEx( $key, $sValue, [], $type, $data, [] ) or warn "C +an't read $hKey\\$sKey: ", regLastError(),"\n"; $error = regLastError(); print "\nError after query: $error"; if ($error ne ""){ RegCloseKey( $key ) or warn "Can't close $hKey\\$sKey: ", reg +LastError(),"\n"; return "error"; } RegCloseKey( $key ) or warn "Can't close $hKey\\$sKey: ", regLast +Error(),"\n"; return "error" if ($error ne ""); return $data; } sub main { my $ret; $ret = getRegistryKeys(HKEY_LOCAL_MACHINE,"SOFTWARE\\ActiveState\\ +ActivePerl1","CurrentVersion"); if ($ret =~ /error/) { print "\nFound error in first attemp..."; $ret = getRegistryKeys(HKEY_LOCAL_MACHINE,"SOFTWARE\\ActiveSta +te\\PerlScript\\1.0","InstallDir"); print "\nSecond attemp: $ret"; } else { print $ret; } }
Output of the script:
Can't open 2147483650\SOFTWARE\ActiveState\ActivePerl: The system cannot find the file specified
Error after open: The system cannot find the file specified
Found error in first attemp...
Error after open: The system cannot find the file specified
Second attemp: error
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Win32API::Registry -- RegOpenKeyEx fails when called 2 times.
by afoken (Chancellor) on Mar 12, 2010 at 13:37 UTC | |
by tye (Sage) on Mar 13, 2010 at 07:27 UTC | |
by afoken (Chancellor) on Mar 14, 2010 at 15:20 UTC | |
by ashah21 (Initiate) on Mar 14, 2010 at 18:03 UTC | |
by ashah21 (Initiate) on Mar 14, 2010 at 18:18 UTC | |
|
Re: Win32API::Registry -- RegOpenKeyEx fails when called 2 times. (subkey ne value)
by tye (Sage) on Mar 12, 2010 at 07:23 UTC | |
|
Re: Win32API::Registry -- RegOpenKeyEx fails when called 2 times.
by cdarke (Prior) on Mar 12, 2010 at 11:27 UTC |