Read a Registry Key

I need a perl script or batch file to read the screen saver on a remote registry, and log it to a file with the machine name and what the screen saver is. I need to feed it a list of machine names.
lamar1Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

lamar1Author Commented:
This is an easy one, but I need it quickly and am in the process of building a new cluster server and don't have time to work on it.
0
thoellriCommented:
Assuming you're using www.activestate.com perl version, you can do the following (this works on NT - not tested on 95,98):


use Win32::TieRegistry;

foreach my $hostname ('host1', 'host2', 'host3') {
  my $saver=screenSaverFor($hostname);
  if (!defined($saver)) {
    print STDERR "Can't retrieve screensaver for host $hostname\n";
    next;
  }
  print "HOST: $hostname   ScreenSaver: $saver\n";
}

sub screenSaverFor {
  my $host=shift;
  $Registry->Delimiter("/");
  eval {
    $key=$Registry->{"//".$host."/HKEY_CURRENT_USER/Control Panel/Desktop/SCRNSAVE.EXE"};
  };
  return $key;
}


Hope this helps
  Tobias
0
lamar1Author Commented:
Ok, I'll try it in the morning, I'm vague on what the list of names is I feed the script, it looks like you are intending that I put each name in the script itself ('host1', 'host2', 'host3') the only problem I see with this is that I have 2700 computers to cut and paste in the script, please correct me if I'm wrong.
Lamar
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

thoellriCommented:
Did you try it on Wednesday 17 1999 in the morning?
0
lamar1Author Commented:
Yes, I did and I couldn't get past the first machine. Do you have a comment about my question on the 16th. I'm sure I'm probably not doing something right.
Can I get some instructions on it's use.Sorry, I didn't get back to you sooner, but I'm unexpectably by myself this week, and it's been the usual madhouse...Thanks Lamar
0
thoellriCommented:
lamar1,

if you happen to have the computer names in a single txt file then you could change the script to this:
use Win32::TieRegistry;

while(<>) {
  chomp;
  my $saver=screenSaverFor($_);
  if (!defined($saver)) {
    print STDERR "Can't retrieve screensaver for host $_\n";
    next;
  }
  print "Host: $_   ScreenSaver: $saver\n";
}

sub screenSaverFor {
  my $host=shift;
  $Registry->Delimiter("/");
  eval {
    $key=$Registry->{"//".$host."/HKEY_CURRENT_USER/Control Panel/Desktop/SCRNSAVE.EXE"};
  };
  return $key;
}

and you would call the script with:

C:\> perl scriptname.pl textfilewithallhostnames.txt

Make sure that the account which runs the script has permissions to access the remote registry without requiring login.

Hope this helps
  Tobias
0
lamar1Author Commented:
Thanks, I'll try it first thing in the morning, and let you know..Lamar
0
lamar1Author Commented:
This works, but I can't seem to get it to write the results to a file. I can only get the first machine or it a zero byte file, can you help. I tried using several different combinations or write statements...Thanks
0
thoellriCommented:
You are new to perl?

use Win32::TieRegistry;

my $logfile="SCREENSAVER.LOG";
open($logfile,">$logfile") || die "can't write to $logfile";

while(<>) {
    chomp;
    my $saver=screenSaverFor($_);
    if (!defined($saver)) {
      print STDERR "Can't retrieve screensaver for host $_\n";
      next;
    }
    print $logfile "Host: $_   ScreenSaver: $saver\n";
}
close($logfile);

sub screenSaverFor {
    my $host=shift;
    $Registry->Delimiter("/");
    eval {
      $key=$Registry->{"//".$host."/HKEY_CURRENT_USER/Control Panel/Desktop/SCRNSAVE.EXE"};
    };
    return $key;
}

Tobias
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
lamar1Author Commented:
Actually, I'm not that new, but I don't use it often. This is what I came up with. At anyrate, your script passes with flying colors, and I'm ready to award you the points. Thanks for your help.

use Win32::TieRegistry;
open (FILE, ">> out.txt");
while(<>) {
  chomp;
  my $saver=screenSaverFor($_);
  if (!defined($saver)) {
    print FILE "Can't retrieve screensaver for host $_\n";
    next;
  }
  print FILE "Host: $_   ScreenSaver: $saver\n";
}

sub screenSaverFor {
  my $host=shift;
  $Registry->Delimiter("/");
  eval {
    $key=$Registry->{"//".$host."/HKEY_CURRENT_USER/Control Panel/Desktop/SCRNSAVE.EXE"};
  };
  return $key;
  close (FILE)
}


0
maneshrCommented:
All,

This question seems to be abandoned. As part of the ongoing cleanup effort, I will leave a note in
the Community Support topic area which will recommend to the Moderators that they close this question.

My recommendation will be to award the points to thoellri.

PLEASE DO NOT AWARD THE POINTS TO ME.

Experts ===>: please leave your thoughts here. <====

maneshr
(NOT a moderator at EE)

0
NetminderCommented:
Per recommendation, force-accepted by
Netminder
CS Moderator
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.