Title: Message
Good Afternoon,
    I am trying to use perl to connect to each machine in my domain, read the value of a registry key, output that to a csv, and move on to the next machine.  For the most part it is successful in doing this.  However, I can't seem to connect consistently to the machines.  I will get a error "Could not connect to machine" from my else statement. I can connect to the machine manually and the registry key is there.  I have tried many different versions of code and I always seem to encounter this problem.  I have enclosed some code that works "most the time".  I know there are also other reasons that could be causing this to occur (outside of perl) but is there a better way to connect to machines?
 
Thank You
john
 
#!/usr/bin/perl -w
 
# This file looks for the SUS registry key..
#
 
use Win32;
use Win32::Registry;
use Win32::NetAdmin;
use Win32::OLE qw{in};
 
#Variable Setup
my $now = scalar localtime();
my $Domain = shift @ARGV || Win32::DomainName();
my @List;
my @filelist;
my $server;
 

$separator = "="x65;
 
##### OPEN output FILE
 
   open (OUTPUT2, ">SUSRegLog.csv") || die ("CAN'T OPEN adminlog.log");
   open (OUTPUT, ">c:\\TEMP\\machinelist.tmp") || die ("CAN'T OPEN machinelist.tmp");
   print (OUTPUT2 "MachineName, Name, Type, Value\n");
 
#------------------------------------
#### Discover machines connected to the network
if (Win32::NetAdmin::GetServers('', $Domain, SV_TYPE_ALL, [EMAIL PROTECTED]))
{
   #DONOTUNCOMMENT#TESTVAR## print (OUTPUT "The machines in the $Domain domain are:\n");
   map
   {
      ####Will print the machines that are connected to the domain
      #DONOTUNCOMMENT#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");
# DONOT UNCOMMENT FOR TESTING ONLY   open (COMPLIST, "c:\\TEMP\\test.tmp") || die ("CAN'T OPEN test.tmp\n");
 
#------------------------------------
 

# declare vars                        
   @filelist=<COMPLIST>;                
#   $part = " ";                         
                                        
## MAIN ##                                        
foreach $listitem (@filelist)        
{                                    
  chomp $listitem;
#Set the registry data types up for display
@registryDataTypes = (
   "REG_NONE",
   "REG_SZ",
   "REG_EXPAND_SZ",
   "REG_BINARY",
   "REG_DWORD",
   "REG_DWORD_BIG_ENDIAN",
   "REG_LINK",
   "REG_MULTI_SZ");
 
$key = "SOFTWARE\\Policies\\Microsoft\\Windows\\WindowsUpdate";
$Check1 = $HKEY_LOCAL_MACHINE->Connect($listitem, $Root);
 
if ($Check1)
{
   print Listitem => $listitem;
   print (OUTPUT2 "$listitem,");
   if ($Root->Open($key, $keyList))
   {
      #print Root => $Root;
      $keyList->GetValues(\%keyValues);
 
      foreach $valueIndex (keys %keyValues)
      {
         print "\nThe index is the same as the name:  $valueIndex\n";
         print "$separator\n";
        
         #The name of the value being retrieved is in the first
         # cell of the array reference
         print "\tName  => $keyValues{$valueIndex}->[0]\n";
         print (OUTPUT2 "$keyValues{$valueIndex}->[0],");
        
         #The data type of the value is in the second cell (cell 1)
         #but the data type is only a number. So that number is
         #used as an index in the data type names array created
         #at the beginning of this program.
  
         print "\tData Type => $registryDataTypes[$keyValues{$valueIndex}->[1]]\n";
         print (OUTPUT2 "$registryDataTypes[$keyValues{$valueIndex}->[1]],");
        
         #The actual value of the key is in cell 2
         print "\tValue => $keyValues{$valueIndex}->[2]\n";
         print (OUTPUT2 "$keyValues{$valueIndex}->[2]\n");
      }
 

      $keyList->Close();
   }
   else
   {
      print "Can not Open $Root\n";
      print (OUTPUT2 "*** $listitem, Can not Open $Root\n");
   }
$Root->Close();
}
else

   print "Can not Connect to $listitem\n";
   print (OUTPUT2 "Can not Connect to $listitem\n");
}
 
}

_____________________________________________________

This email is confidential and intended solely for the use of

the individual or organization to whom it is addressed. Any

opinions or advice presented are solely those of the author

and do not necessarily represent those of the Millward Brown

Group of Companies. DO NOT copy, modify, distribute or

take any action in reliance on this email if you are not the

intended recipient. If you have received this email in error

please notify the sender and delete this email from your system.

Although this email has been checked for viruses and other

defects, no responsibility can be accepted for any loss or

damage arising from its receipt or use.

______________________________________________________


Reply via email to