Hello,
I have a script I am trying to use to query a particular registry value on all machines attached to a network. It is querying the DC correctly and creating that list. It is parsing the list correctly and even is
Attaching to the registry correctly. My issue is that it is not finding the registry KEY consistently. For example if I run the script say 3 times on a machine XYZ. It may only return the value 1 out of the 3 times that it is queried. The other times it lists my output from the last else statement: Key not present. My thought was that it was having drops on the network so I have tried putting this in a loop so that it will query each machine 6 times if it does not get a value, but this does not seem to help. It either finds the value on the first try or not at all.
If anyone has any suggestions I would be grateful.
Thank you,
John
#!/usr/bin/perl -w
# This file Reads the build registry key..
#
#### Includes #####
use strict;
use Win32;
use Win32::NetAdmin;
use Win32::Registry;
use Win32::TieRegistry( Delimiter=>"/" );
#### Variable Setup ####
my @List;
my $Domain = shift @ARGV || Win32::DomainName();
my $key;
my $BuildValue;
my @filelist;
my $listitem;
#$separator = "="x65;
my $now = scalar localtime();
#### OPEN output FILE that contains machines connected to the network
open (OUTPUT, ">c:\\TEMP\\machinelist.tmp") || die ("CAN'T OPEN machinelist.tmp");
#### OPEN output FILE that contains the build values and set headers
open (FINAL_OUTPUT, ">BuildVersions$Domain.csv") || die ("CAN'T OPEN BuildVersions.txt");
print (FINAL_OUTPUT "$now \n");
print (FINAL_OUTPUT "DOMAIN , Machine , Statement\n");
#### Discover machines connected to the network
if (Win32::NetAdmin::GetServers('', $Domain, SV_TYPE_ALL, \@List))
{
##TESTVAR## my $iCount;
##TESTVAR## print (OUTPUT "The machines in the $Domain domain are:\n");
map
{
####Will print the machines that are connected to the domain
#chop $_;
print (OUTPUT "$_ \n");
} @List;
}
else
{
print (OUTPUT Win32::FormatMessage(Win32::Lanman::GetLastError()));
}
#### CLOSE output FILE that contains machines connected to the network
close OUTPUT;
#### Open File (machinelist.ini) containing machines to have registry key checked
open (COMPLIST, "c:\\TEMP\\machinelist.tmp") || die ("CAN'T OPEN machinelist.tmp\n");
#### declare vars
@filelist=<COMPLIST>;
# my $iCount;
# for ($filelist[$iCount]) {
# print "$filelist[$iCount]\n";
# $iCount++;
# }
#### MAIN ####
foreach $listitem (@filelist)
{
my $i=0;
chomp $listitem;
print "\n\n$listitem\n";
#### USE of KEY --> $remoteKey= $Registry->{"//HostName/LMachine/"};
while ($i <= 5)
{
print $i;
if ($key = $Registry->Open("//$listitem/LMachine/Software/ab1/Bld", {Access=>KEY_READ}))
{
print "Opening Registry try $i\n";
if ($BuildValue = $key->GetValue("BldV"))
{
print FINAL_OUTPUT "$Domain , $listitem , $BuildValue\n";
$i=6;
print "Success\n";
}
else
{
print FINAL_OUTPUT "\nCan't attach to read key on $listitem\n";
}
print "Closing registry key\n";
#exit 0;
undef $key;
#$key->Close();
}
else
{
if ($i <= 4)
{
$i++;
}
else
{
$i=6;
print FINAL_OUTPUT "$Domain , $listitem , Key not present. Times tried: $i\n";
}
}
} # end while
} # end for loop
