Link to home
Start Free TrialLog in
Avatar of lamar1
lamar1

asked on

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.
Avatar of lamar1
lamar1

ASKER

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.
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
Avatar of lamar1

ASKER

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
Did you try it on Wednesday 17 1999 in the morning?
Avatar of lamar1

ASKER

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
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
Avatar of lamar1

ASKER

Thanks, I'll try it first thing in the morning, and let you know..Lamar
Avatar of lamar1

ASKER

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
ASKER CERTIFIED SOLUTION
Avatar of thoellri
thoellri

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
Avatar of lamar1

ASKER

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)
}


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)

Per recommendation, force-accepted by
Netminder
CS Moderator