Newbie Question

Simon336697
Simon336697 used Ask the Experts™
on
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
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2009

Commented:
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);

Author

Commented:
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.
Top Expert 2009

Commented:
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);
OWASP: Threats Fundamentals

Learn the top ten threats that are present in modern web-application development and how to protect your business from them.

Author

Commented:
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.
Top Expert 2009

Commented:
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);

Author

Commented:
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.
Top Expert 2009
Commented:
That means it is connecting at the HKEY_USERS branch... try this version to clean it up then:


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 "$_: AutoEndTasks=" . $remRegistry->{".DEFAULT/Control Panel/Desktop/AutoEndTasks"} . "\n";
      close(OUT);
}

close(OUT);
close(IN);

Author

Commented:
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
Top Expert 2009

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

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial