Link to home
Start Free TrialLog in
Avatar of Simon336697
Simon336697Flag for Australia

asked on

Newbie Question

Hi guys!

Hope you can help.

Im a newbie to perl.

We are running activestate perl on xp boxes, and Id like to do the following.

I have a list of computers in a text file (computers.txt), in format

computer1
computer2
etc
etc

What Id like to do is write a .pl script to:

1) Read the computer names from computers.txt
2) Connect to each computer and authenticate as <local computer>\administrator with password 'password'. Note that <local computer> needs to be read in from the computers.txt file.
So, if I connect to computer1, then user is computer1\administrator, computer2 - computer2\administrator, and so on.
3) Read the following registry key:
HKEY_USERS\.DEFAULT\Control Panel\Desktop\Autoendtasks
4) Dump the results into a test file called results.txt

While the perl script is running, it would be great if there was a status of what computer the script is up to on the screen.

Thanks guys for any help.

S
Avatar of Adam314
Adam314

use Data::Dumper;
use Win32::TieRegistry;

my $Registry = new Win32::TieRegistry or  die "Can't access HKEY_LOCAL_MACHINE key: $^E\n";

open(IN,"<computer.txt") or die "Could not open computer.txt: $!\n";
open(OUT,">>results.txt") or die "Could not open results.txt: $!\n";
while(<IN>) {
      print "Currently working on $_\n";
      unless($remRegistry = $Registry->Connect( $_, "HKEY_USERS", {Delimiter->"/"} ) ){
            print "    Could not connect to $_: $^E\n";
            return;
      }
      print OUT Dumper($remRegistry->{".DEFAULT/Control Panel/Desktop/Autoendtasks"});
      close(OUT);
}

close(OUT);
close(IN);
Avatar of Simon336697

ASKER

Hi Adam!

Thank you so much for this I really appreciate your help.

I ran the code but got the following tho Adam...

C:\Test>test.pl
String found where operator expected at C:\Test\gold.pl line 10, near "->"/""
        (Missing operator before "/"?)
syntax error at C:\Test\gold.pl line 10, near "->"/""
syntax error at C:\Test\gold.pl line 13, near "}"
Execution of C:\Test\gold.pl aborted due to compilation errors.
use Data::Dumper;
use Win32::TieRegistry;

my $Registry = new Win32::TieRegistry("HKEY_USERS") or  die "Can't access HKEY_LOCAL_MACHINE key: $^E\n";

open(IN,"<computer.txt") or die "Could not open computer.txt: $!\n";
open(OUT,">>results.txt") or die "Could not open results.txt: $!\n";
while(<IN>) {
      print "Currently working on $_\n";
      unless($remRegistry = $Registry->Connect($_, "HKEY_USERS", {Delimiter=>"/"} ) ){
            print "    Could not connect to $_: $^E\n";
            return;
      }
      print OUT Dumper($remRegistry->{".DEFAULT/Control Panel/Desktop/Autoendtasks"});
      close(OUT);
}

close(OUT);
close(IN);
Hi Adam!

Thank you. It ran fine this time.

However I looked at the results.txt, and it had the following line.

$VAR1 = undef;

HKEY_USERS\.DEFAULT\Control Panel\Desktop\Autoendtasks has a value of 0.

Im not sure that the $VAR1 means.
I can't test the remote connection part.... I'm not sure if it connects at the root, or at HKEY_USERS.  Try like this:

use Win32::TieRegistry;

open(IN,"<computer.txt") or die "Could not open computer.txt: $!\n";
open(OUT,">>results.txt") or die "Could not open results.txt: $!\n";
while(<IN>) {
      print "Currently working on $_\n";
      unless($remRegistry = $Registry->Connect($_, "HKEY_USERS", {Delimiter=>"/"} ) ){
            print "    Could not connect to $_: $^E\n";
            return;
      }
      print OUT Dumper($remRegistry->{"HKEY_USERS/.DEFAULT/Control Panel/Desktop/AutoEndTasks"});
      print OUT Dumper($remRegistry->{".DEFAULT/Control Panel/Desktop/AutoEndTasks"});
      close(OUT);
}

close(OUT);
close(IN);
Hi Adam!

It returned the correct value this time, the output was 2 lines long..

$VAR1 = undef;
$VAR1 = '6';

Still giving a undef value.

I only have one entry in the computer.txt, which is the local machine.
ASKER CERTIFIED SOLUTION
Avatar of Adam314
Adam314

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Adam it works!!!!!
Thank you SO MUCH.
Adam you have the points clearly.
Can I just ask you........If you wanted to, instead of just printing out the key and value, eg. my results.txt file is as follows..

dell101: AutoEndTasks=6

If I wanted to do print out the whole registry path:

dell101: HKEY_USERS\.DEFAULT\Control Panel\Desktop\AutoEndTasks=6

Do you know how to do this?

Thanks Adam.

Simon
print OUT "$_: HKEY_USERS\\.DEFAULT\\Control Panel\\Desktop\\AutoEndTasks=" . $remRegistry->{".DEFAULT/Control Panel/Desktop/AutoEndTasks"} . "\n";