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

I am having a rather curious problem looking for a subkey on a remote registry using Win32::TieRegistry. I am looking for a subkey under "HKLM/SYSTEM/CurrentControlSet/Services". I can see the subkey w/ regedit when I connect to the remote box but it never shows if I print out the hash. I would think that if this were a permissions problem I would never be able to connect using regedit. The error returned from regLastError() is "The system cannot find the file specified". Of course, everything works fine when the script is run on the remote box. Any suggestions??
use Getopt::Long; use Win32::TieRegistry; use Win32API::Registry qw( regLastError ); my ($machine, $help, $remote_key, $entry); my $root_key = "HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/a +llisbus/Parameters/Session"; GetOptions( "h" => \$help, "m" => \$machine, ); if ($machine) { $machine = "//$machine" } $Registry->Delimiter("/"); $remote_key = $Registry->{"$machine/$root_key"} or die "Can't read $ro +ot_key: ", regLastError(), "\n"; while (($key, $value) = each(%$remote_key)) { if ($key =~ /allisbus/) { print "Found: $key\n"; } print "Reg key\t: $key, Reg value\t: $value \n"; }

Replies are listed 'Best First'.
Re: Remote Win32::TieRegistry
by thunders (Priest) on Jul 03, 2002 at 18:16 UTC
    I've had issues with using the full keyname HKEY_LOCAL_MACHINE in most cases replacing that with the shortcut LMachine works better on remote pcs.
    my $remote_key = $Registry->{"//$machine/LMachine/SYSTEM/". "CurrentControlSet/Services/". "allisbus/Parameters/Session"}
      That was a thought that I tried as well. When I use "//$machine/LMachine/SYSTEM/CurrentControlSet/Services" the subkey "allisbus" still does not show up and I still can't get to it directly. Very irritating. Could it have something to do with the way InstallShield installs registry subkeys??
(tye)Re: Remote Win32::TieRegistry
by tye (Sage) on Jul 03, 2002 at 21:14 UTC

    End with ".../Parameters/Session/" instead of leaving off that final "/". This tells TieRegistry that you want the key "Session" and not the value "Session". Yes, it should work either way, but I suspect you've found a bug in regard to that.

    Please let me know if that works.

            - tye (but my friends call me "Tye")
      Good idea but still no go. It know this is strange, but I can manipulate this key remotely with both regedit & regedt32 w/out any problems. I would assume they are using the same file (winreg.h) that Win32API::Registry is. I just wish I could get a more illluminating error message from M$.

        Another common problem is that TieRegistry, by default, requests quite a bit of access to the keys that it opens. This is most commonly a problem when someone wants read-only access to a key. This problem should produce a different error reason than the one you reported, but perhaps not in this case for some reason.

        So try specifying that you want less access to the key and see if that helps:

        $remote_key = $Registry->Open( "$machine/$root_key", { Access => "KEY_READ" } ) or die "Can't read $root_key: ", regLastError(), "\n";
        For more sophisticated control over the level of access, you'll need to import some symbols:
        use Win32::TieRegistry qw( :KEY_ ); # ... $remote_key = $Registry->Open( "$machine/$root_key", { Access => KEY_READ()|KEY_SET_VALUE() } ) or die "Can't read $root_key: ", regLastError(), "\n";

                - tye (but my friends call me "Tye")