in reply to Re^3: Win32API::Registry -- RegOpenKeyEx fails when called 2 times. (our 2^H3 main weapons)
in thread Win32API::Registry -- RegOpenKeyEx fails when called 2 times.
Thanks All for your valuable responses.
As tye said, my presentation is bit confusing.. So let me try to explain the problem again.
I have to get the value of one subkey which might be present under wow6432node (e.g. SOFTWARE/Wow6432Node/Microsoft/Internet Explorer) location or under the original 32/64 bit (e.g. SOFTWARE/Microsoft/Internet Explorer) registry. So I had put them in if-else.
The problem I was facing was, if the first key does not exist then my code (posted on the original thread) is not able to find the second key as well even though it exists at that location.
The reason behind the problem was, I was relying on the regLastError to decide if 'RegOpenKeyEx' function has returned success or not.
Following code works fine for me now:RegOpenKeyEx( $hKey, $sKey, 0, KEY_READ, $key) or warn "Can't ope +n $hKey\\$sKey: ", regLastError(),"\n"; $error = regLastError(); return "error" if ($error ne "");
RegOpenKeyEx( $hKey, $sKey, 0, KEY_READ, $key) or warn "Can't ope +n $hKey\\$sKey: ", regLastError(),"\n"; RegQueryValueEx( $key, $sValue, [], $type, $data, [] ) or warn "C +an't read $hKey\\$sKey: ", regLastError(),"\n"; RegCloseKey( $key ) or warn "Can't close $hKey\\$sKey: ", regLastE +rror(),"\n"; chomp($data); return $data;
|
|---|