Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling

Re: access 64bit registry from 32 bit Perl

by GrandFather (Sage)
on Dec 05, 2012 at 03:08 UTC ( #1007183=note: print w/replies, xml ) Need Help??

in reply to access 64bit registry from 32 bit Perl

I use the following sub to grovel through registry looking for installers which may be of interest to you:

sub FindXXXSoftware { my ($resetNoModify) = @_; return if !$^O eq 'MSWin32'; my @result; eval { require 'Win32/'; require 'Win32/'; require 'Win32API/'; my $pathPrefix = 'LMachine\SOFTWARE'; my $wowPath = 'Wow6432Node'; my $pathSuffix = 'Microsoft\Windows\CurrentVersion\Uninstall'; my $root = Win32::TieRegistry->new($pathPrefix, {Access => Win32API::Registry::KEY_READ()}); my @products; for my $subPath ($pathSuffix, "$wowPath\\$pathSuffix") { my $uninstall = $root->Open($subPath); next if !$uninstall; $uninstall->Flush(); my @entries = $uninstall->SubKeyNames(); for my $entry (@entries) { my $entryKey = $uninstall->Open($entry); my $name = $entryKey->GetValue('DisplayName'); my $pub = $entryKey->GetValue('Publisher'); my $noModify = $entryKey->GetValue('NoModify'); next if !defined $name || !defined $pub || $pub !~ /^XXX/i; eval { delete $entryKey->{NoModify}; return 1; } or warn "Registry DeleteValue failed for 'NoModify' agains +t $name\n" if defined $noModify && $resetNoModify; push @result, {entryCode => $entry, name => $name}; } } return 1; }; return @result; }
True laziness is hard work

Replies are listed 'Best First'.
Re^2: access 64bit registry from 32 bit Perl
by anaconda_wly (Scribe) on Dec 05, 2012 at 15:58 UTC

    Thanks for your code.

    It took me some time to understand. But sorry maybe I didn't catch the point, for I didn't see how you resolve the problem of 32bit program accessing a 64bit program's registry in 64bit OS

    In fact, any trying of accessing to "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" will be redirected to "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\" automatically. That means I can never get content of "HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" branch, which is what I want using a 32bit Perl program and different from "HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\"

    The Perl code I wrote is like what you have written somewhat, but didn't work as I wished. I spent a lot of time to check why I didn't get the correct content as seeing from regedit. Later I understand by searching websites that the WoW64 is doing the redirecting...

      I had a similar problem and solved it like:
      use Win32API::Registry qw(:ALL); ... if( RegOpenKeyEx( HKEY_LOCAL_MACHINE, "SOFTWARE\\Microsoft\\Cryptograp +hy", 0, KEY_READ|0x0100, $key ) ) { RegQueryValueEx($key, "MachineGuid", [], $type, $nodeId, []); RegCloseKey( $key ); }
      The point is 'KEY_READ|0x0100'. From
      #define KEY_WOW64_64KEY 0x0100 Access a 64-bit key from either a 32-bit or 64-bit application.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1007183]
[erix]: haha Chump's handshake shaken
[erix]: surely such a handshake is enough to impeach the idiot :)

How do I use this? | Other CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2017-05-24 06:59 GMT
Find Nodes?
    Voting Booth?