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?
 
thoellriConnect With a Mentor Commented:
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
 
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
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
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
 
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
 
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
All Courses

From novice to tech pro — start learning today.