#******************************************************************************
# Name:		HotFixCheck.pl
# By:		Robert Spitzer
# Email:	robert.spitzer@ngc.com
#
# The purpose of this script is to check a group of computers for a particular
# hotfix.
#
# Usage:	HotFixCheck.pl [computer list] [hotfix number] [output file]
#
# Version:	1.0.0
# Created:	08/05/03	Revised:	00/00/00
#******************************************************************************
# Modules used by this script
use Win32::TieRegistry;

# If no arguements are provided, print out help information.
if($ARGV[0] eq "/?" || @ARGV < 3) {
	Usage();
	exit 1;
}

# Variables used by this script
$HotFix  = $ARGV[1];
$RegPath = "LMachine\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\HotFix";

# Open the computer list file and output file for processing
open (COMPLIST, "<$ARGV[0]") || die "Couldn't open the file $ARGV[0]\n";
open (OUTFILE, ">$ARGV[2]") || die "Couldn't open the file $ARGV[2]\n";

# Print out the output file header
print OUTFILE "Computer, HotFix Status\n";

# Loop through the computer list and perform the search
while ($Computer = <COMPLIST>) {
	chomp $Computer;
	print "Now processing $Computer\n";

	$Status = "Not Installed"; # Reset the status variable

	# Connect to the registry for the given computer
	$RegKey = $Registry->{"\\\\$Computer\\$RegPath\\"};

	if ($RegKey eq "") { $Status = "Error"; }

	else {
		# Loop through the registry subkeys looking for the hotfix
		foreach $SubKey ($RegKey->SubKeyNames) {
			if ($SubKey =~ /$HotFix/) { $Status = "Installed"; }
		}
	}

	# Output the results
	print OUTFILE "$Computer, $Status\n";
}

# Close the connections to the input and output files
close COMPLIST;
close OUTFILE;

#****************************************************************************
sub Usage {

print <<USAGE

HotFixCheck v1.0.0
Written by: Robert Spitzer

The purpose of this script is to check a group of computers for a particular
hotfix.

Usage:	HotFixCheck [computer list] [hotfix number] [output file]

USAGE

}