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

Hello fellow monks,

The background to this is that I want to do some low-level poking of the Windows registry on 64bit Windows (it's related to the WOW64 registry reflection nonsense).

I'm going to use Win32API::Registry to return the handle to a key, which I'll then use with Win32::API to call RegQueryReflectionKey() which is exposed through AdvApi32.dll.

So, I thought I'd start small and write up a few lines to make sure Win32API::Registry works as I think it should:

use strict; use warnings; use Win32API::Registry 0.22 qw ( :ALL ); my $sSubKey = "SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Winlog +on\\DefaultDomainName\\"; my $ohSubKey; RegOpenKeyEx( HKEY_LOCAL_MACHINE, $sSubKey, 0, KEY_READ, $ohSubKey ) o +r die regLastError(); print "$ohSubKey\n";

When I run this, it dies with the error:

The system cannot find the file specified at xx.pl line 12.

So, my question is this, am I doing something wrong? If I use regmon from sysinternals it shows that the Perl process is querying and opening the key (and the key certainly exists) - so why is it breaking and not returning a handle?

CPAN says the latest version of 0.23, but I can only find 0.22 even with all the extra PPM registries I have added in... Incidentally, Win32::TieRegistry works just fine, which I think is just a wrapper around Win32API::Registry.

Replies are listed 'Best First'.
Re: Win32API::Registry Troubles (same)
by tye (Sage) on Nov 16, 2005 at 14:56 UTC

    You can't use RegOpenKeyEx() to open a value. It is just the same as the C API.

    You might prefer to use Win32::TieRegistry and it's Handle() method.

    - tye        

      Doh! Obvious now you say it! tye++

Re: Win32API::Registry Troubles
by holli (Abbot) on Nov 16, 2005 at 13:53 UTC
    use strict; use warnings; use Win32::Registry; my $key = $HKLM->OpenEx("SOFTWARE\\Microsoft\\Windows NT\\CurrentVersi +on\\Winlogon"); #"); print $key->GetValue("DefaultDomainName");


    holli, /regexed monk/

      Ah, am I missing something else then? I'm not actually after the value of that key, rather, the handle that was used to open it.

      From the Win32API::Registry documentation:

      RegOpenKeyEx( $hKey, $sSubKey, $uOptions, $uAccess, $ohSubKey )

      $ohSubKey will be set to the handle to be used to access the new subkey if the call succeeds.

      (It's also possible there are some typos in the POD on CPAN...)