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

I need to access the registry of remote windows machines. I was looking at the documentation for Win32::TieRegistry, but i don't see any information on connection to a remote machine (and provide the username and password to connect to that machine).

How does one go about doing this?

Replies are listed 'Best First'.
Re: Remote Windows Registry (extramodular)
by tye (Sage) on Oct 10, 2003 at 20:38 UTC

    If it doesn't work with the credentials the script is run under, then you can use something hackish like:

    system("net use \\\\$computer /user:$user $password")
    or use Win32::NetResource's AddConnection() to authenticate to the remove computer before you try to connect to the remote registry.

                    - tye
      I've had problems using the system call to pass the "net use" command. I can't get it to work just using "net use \\\\$computer ..." and I've had no success using system("net use \\\\$computer\\ipc\$...." No matter how I delimit the IPC$ parameter, it ignores the $. Very frustrating. I eventually came up with the use Win32::Lanman module used in the following manner (this example gets the OS Version from the registry):
      use Win32::TieRegistry(Delimiter => "/", ArrayValues => 0); use Win32::Lanman; $host = "10.10.10.10"; $pass = "yourpass"; $user = "youradmin"; $domain = "yourdomain"; if(!Win32::Lanman::NetUseAdd({remote => "\\\\$host\\ipc\$", password => "$pass", username => "$user", domain => "$domain", asg_type => &USE_IPC})) { print "connect: Sorry, something went wrong; error: "; # get the error code print Win32::Lanman::GetLastError(); exit 1; } $remoteKey = $Registry->{ "//$host/LMachine/SOFTWARE/Microsoft/Windows NT/Curre +ntVersion/ProductName"} or die "Can't read from $host. Error: $^E\n"; print "$remoteKey\n"; if(!Win32::Lanman::NetUseDel("\\\\$host\\ipc\$")) { print "disconnect: Sorry, something went wrong; error: "; # get the error code print Win32::Lanman::GetLastError(); exit 1; }
      Hope this helps. If anyone has a more elegant solution, I'd love to hear about it!
Re: Remote Windows Registry
by jasonk (Parson) on Oct 10, 2003 at 19:33 UTC

    There is an example in the documentation for tieing to a remote registry...

    use Win32::TieRegistry( Delimiter=>"/", ArrayValues=>0 ); $remoteKey= $Registry->{"//ServerA/LMachine/System/"} or die "Can't r +ead //ServerA/LMachine/System/ key: $^E\n";

    You will need to have permission to access that registry as the user you are running the script as, I don't believe there is any mechanism provided for you to provide alternate credentials to Win32::TieRegistry.


    We're not surrounded, we're in a target-rich environment!