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

Hi,
We have a Perl program that ran well on all Windows platforms so far.
When we tried it on the newly released Windows Server 2008 R2, it stopped working. Investigation revealed that the problem is that calls to read registry values using TieRegistry returned undefined values.

Is this a known problem? Did anyone run into a problem accessing the registry on Windows Server 2008 R2 using TieRegistry?
I'm running the program as administrator, so I don't think it is permission problems. The program works great and read the registry correctly on Windows 7 and Vista.

A sample script I wrote to access the registry also fail:
use Win32::TieRegistry(Delimiter=>'\\'); my $reg = "HKEY_LOCAL_MACHINE\\SOFTWARE\\TEST\\Value1"; my $val = $Registry->{$reg}; print "val: ".$val."\n";

Any help would be appreciated.

Thanks,
splintor

Replies are listed 'Best First'.
Re: TieRegistry and Windows Server 2008 R2
by Anonymous Monk on Oct 25, 2009 at 14:16 UTC
    Why no error checking?
Re: TieRegistry and Windows Server 2008 R2
by splintor (Initiate) on Oct 26, 2009 at 19:36 UTC
    I found the source of my problem.

    In order to make TieRegistry work well on 64-bit Windows, and access the correct registry hive, we used the solution suggested by Tony B. Okusanya (also quoted here). However, this solution adds both KEY_WOW64_64KEY and KEY_WOW64_32KEY to the access parameter, which is not logical – either you want to access the 64-bit registry and use KEY_WOW64_64KEY or you want the 32-bit registry and use KEY_WOW64_32KEY. Using both doesn’t make any sense.

    Nevertheless, in previous versions of Windows, as well as Windows 7, it seems that when RegOpenKeyEx notices that the KEY_WOW64_64KEY flag is set in the access parameter, it uses the 64-bit registry, and ignores the KEY_WOW64_32KEY flag. Windows Server 2008 R2, on the other hand, doesn’t ignore the KEY_WOW64_32KEY flag, and if both flags are set, opening the registry key fail, and Win32API::Registry.regLastError returns the error “The parameter is incorrect”.

    Removing “|KEY_WOW64_32KEY” from our changed TieRegistry.pm solved the problem and caused our application to work again.

    Regards,
    splintor

      I managed to use KEY_WOW64_32KEY and KEY_WOW64_64KEY without modifying Win32::TieRegistry:

      use Win32::TieRegistry qw(:KEY_); sub KEY_WOW64_64KEY {return 0x100;} sub KEY_WOW64_32KEY {return 0x200;} my $Reg32={}; my $Reg64={}; new Win32::TieRegistry("HKEY_LOCAL_MACHINE", { Delimiter=>'/', Access=> KEY_READ|KEY_WRITE|KEY_CREATE_SUB_KEY|KEY_WOW64_32KEY } ) ->Tie($Reg32); new Win32::TieRegistry("HKEY_LOCAL_MACHINE", { Delimiter=>'/', Access=> KEY_READ|KEY_WRITE|KEY_CREATE_SUB_KEY|KEY_WOW64_64KEY } ) ->Tie($Reg64);