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

use Win32::TieRegistry; $REMOTE= $Registry->Connect( '127.0.0.1','LMachine',{Delimiter=>"\\"} +) or die; my $key_to_save="SOFTWARE\\"; $success=$REMOTE->{$key_to_save}->AllowSave( 1 ); if ($success){ $REMOTE->{$key_to_save}->RegSaveKey( "c:\\sioln.reg", [] ) or die $^E; }else{print $^E;}
I was surprised when change 127.0.0.1 on other host IP.
The file was saved on remote C$ :)
Is there any way to save it on my disk? (Not moving from remote host)

And what can I wait from loadkey on remote host? I'll need to place the *.reg file on remote host localy before trying to load?
  • Comment on Win32::TieRegistry - RegSaveKey saves on remote hosts disk but not mine.
  • Download Code

Replies are listed 'Best First'.
Re: Win32::TieRegistry - RegSaveKey saves on remote hosts disk but not mine.
by john_oshea (Priest) on Jan 20, 2006 at 13:59 UTC

    The Win32::TieRegistry docs mention that "The $file path is interpreted relative to %SystemRoot%/System32/config on the machine where $key resides". Assuming the remote machine has write access to your machine, I imagine that replacing "c:\\" with "\\NAME_OF_YOUR_MACHINE\some\writable\path" would work (though you'd probably have to fiddle with the number of slashes - am not on a Windows box to be able to check).

    Assuming that you can use UNC paths, then LoadKey should work in the same manner. Hope that helps

      $REMOTE->{$key_to_save}->RegSaveKey( "//127.0.0.1/C$/sioln1.reg", [] ) + or die $^E;
      dead: Network path not found :(
      $REMOTE->{$key_to_save}->RegSaveKey( "\\\\127.0.0.1\\C\$\\sioln1.reg", + [] ) or die $^E;
      Creates on remote host :(

        127.0.0.1 may well be being interpreted as the remote machine, not yours - what happens if you explicitly use either your machine's name, or a non-127.* address?

        Update:

        Further poking around reveals that RegSaveKey and RegLoadKey are defined in Win32API::Registry, which mentions the following:

        WARNING:  Loading of hive files via a network share may silently
        corrupt the hive and so should not be attempted (this is a problem
        in at least some versions of the underlying API which this module
        does not try to fix or avoid).  To access a hive file located on a
        remote computer, connect to the remote computer's Registry and load
        the hive via that.

        Which seems to imply that it is possible to do this remotely.

Re: Win32::TieRegistry - RegSaveKey saves on remote hosts disk but not mine. (Connect?)
by tye (Sage) on Jan 20, 2006 at 17:42 UTC

    Why do you keep using Connect() to 127.0.0.1? If you want to access the registry on the local computer, you might want to use Open (or any of several other documented ways) other than Connect(). It might prevent some strange behavior.

    - tye