http://www.perlmonks.org?node_id=170633
LovelyGreeting has asked for the wisdom of the Perl Monks concerning the following question:

I'm looking for Perl solution to monitor execution status of Win32 task scheduler, like 'status' and 'last result'. It seems there are two solutions: Win32::Lanman and Win32::AdminMisc. I have downloaded the code. It runs silently, nothing back. Codes listed for your reference. Any feedback will be greatly appreciated!
#============================= # Win32::AdminMisc #============================= use win32::adminmisc; $Jobs = Win32::AdminMisc::ScheduleList("\\\\server01", \%Jobs); print "==>".%Jobs."\n"; foreach $Number (keys(%Jobs)){ print "Job $Number is $Jobs{$Number}->{Command}\n"; }
#============================= # Win32::Lanman #============================= use Win32::Lanman; use Win32::NetAdmin; @ARGV[0]; if (@ARGV[0] eq ""){print "\n\nSyntax\n\n\ttasks.pl servername\n\ttask +s.pl all\n\n"; exit 1;} if ("\U@ARGV[0]\E" eq "ALL"){&getservers;} else {@servers = ("@ARGV[0] +");} $output = "C:\\temp\\task.txt"; open(OUTPUT, ">$output") || die "Can't open $output"; %DOW = ( 0,'', 1,'Monday', 2,'Tuesday', 4,'Wednesday', 8,'Thursday', 16,'Friday', 32,'Saturday', 64,'Sunday' ); %DOM = ( 0,'', 1,'1', 2,'2', 4,'3', 8,'4', 16,'5', 32,'6', 64,'7', 128,'8', 256,'9', 512,'10', 1024,'11', 2048,'12', 4096,'13', 8192,'14', 16384,'15', 32768,'16', 65536,'17', 131072,'18', 262144,'19', 524288,'20', 1048576,'21', 2097152,'22', 4194304,'23', 8388608,'24', 16777216,'25', 33554432,'26', 67108864,'27', 134217728,'28', 268435456,'29', 536870912,'30', 1073741824,'31' ); %FLAG = ( 1,'Reoccuring job - Interactive', 3,'Reoccuring job - Interactive - Error when last run', 4,'One time job - Will run today - Interactive', 5,'Reoccuring job - Will run today - Interactive', 17,'Reoccuring job - Non-Interactive', 19,'Reoccuring job - Not Interactive - Error when last run', 20,'One time job - Will run today - Not Interactive', 21,'Reoccuring job - Will run today - Not Interactive' ); foreach $server (@servers) { print "querying $server\n"; if(!Win32::Lanman::NetScheduleJobEnum("\\\\$server", \@jobs)) { print "\n\nUnable to read scheduled jobs from $server\n\n"; next; } print "==>".@jobs."\n"; foreach $job (@jobs) { print OUTPUT "server = $server\n"; @keys = keys %$job; $job->{'daysofweek'} = $DOW{$job->{'daysofweek'}}; $job->{'daysofmonth'} = $DOM{$job->{'daysofmonth'}}; $job->{'flags'} = $FLAG{$job->{'flags'}}; $runtime = ${$job}{'jobtime'}/1000; $hour = sprintf("%02d", (int ($runtime / 3600))); $min = sprintf("%02d", (int ((($runtime - ($hour * 3600)) / 60 +)))); $job->{'jobtime'} = "$hour:$min"; foreach $key (@keys) { print OUTPUT "$key = ${$job}{$key}\n" if (${$job}{$key} ne + ""); } print OUTPUT "\n---------------------------------------------- +----------\n\n"; } } print "==>".@jobs."\n"; close OUTPUT; sub getservers { my (@servers1, @servers2, @servers3); print "\nLooking up server names\n\n"; my $domain = Win32::DomainName; Win32::NetAdmin::GetDomainController("", $domain, $PDC) || print " +Unable to obtain the PDC name for $domain."; Win32::NetAdmin::GetServers($pdc, $domain, 0x00000008, \@servers1) + || print "Unable to read NetBios 0008."; Win32::NetAdmin::GetServers($pdc, $domain, 0x00000010, \@servers2) + || print "Unable to read NetBios 0010."; Win32::NetAdmin::GetServers($pdc, $domain, 0x00008000, \@servers3) + || print "Unable to read NetBios 8000."; @servers = (@servers1, @servers2, @servers3); }