Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??
Dear Courage, I wolud love to appreciate for all you have done. After tried the WMI approach, it can get all AT instances, but can't see any instance created by Task Scheduler UI program. However, your MSDN research lights me up. After several search in MSDN, I found COM objects called Task Scheduler API and one sample C++ code. It works on instances created by Task Scheduler UI Program. Then, I found another Perl extension Win32-TaskScheduler, created by Umberto Nicoletti. You can find it at http://taskscheduler.sourceforge.net. I'm not familiar with Perl, COM, OLE, but still tried to build a simple example querying the status of remote machine's Task Scheduler instances. Attached for your reference: Thank you very much!!
use strict; use Win32::TaskScheduler; (my $Machine = shift @ARGV || "" ) =~ s/^[\\\/]+//; my $scheduler; my @jobs; my $job; my $jobname; my $account; my $APname; my $parameter; my $workdir; my $triggerCnt; my $idx; my %trigger; my $key; my $trigType; my $flags; my $status; my $exitcode; $scheduler = Win32::TaskScheduler->New(); if ( $Machine ) { $scheduler->SetTargetComputer("\\\\".$Machine) or die("Failed: Set + Server Machine:".$Machine."\n"); } @jobs = $scheduler->Enum(); foreach $job ( @jobs ) { $jobname = substr($job,0,length($job)-4); $scheduler->Activate($jobname) or die("Failed: Activate".$job." [" +.$jobname."]\n"); print "==>".$job." [".$jobname."]\n"; $APname = $scheduler->GetApplicationName(); if ( $APname ) {print "\tAPname:".$APname."\n";} $parameter = $scheduler->GetParameters(); if ( $parameter ) {print "\tParameter:".$parameter."\n";} $workdir = $scheduler->GetWorkingDirectory(); if ( $workdir ) {print "\tWorkDir:".$workdir."\n";} $account = $scheduler->GetAccountInformation(); if ( $account ) {print "\tAccount:".$account."\n";} $scheduler->GetExitCode($exitcode); print "\tExitCode:".$exitcode."\n"; $scheduler->GetStatus($status); if ( $status == 267008 ) { #Ready print "\tStatus:ready\n"; } elsif ( $status == 267009 ) { #Runnig print "\tStatus:RUNNING\n"; } elsif ( $status == 267010 ) { #Not Scheduled print "\tStatus:Not Scheduled\n"; } else { print "\tStatus:UNKNOWN\n"; } $flags = $scheduler->GetFlags(); if ( $flags ) {print "\tFlags:".$flags."\n";} $triggerCnt = $scheduler->GetTriggerCount(); if ( $triggerCnt > 0 ) { for ( $idx = 0; $idx < $triggerCnt; $idx++ ) { print "\tTrigger $idx:\n"; $scheduler->GetTrigger($idx,\%trigger); foreach $key (keys %trigger) { if ( $key eq "TriggerType" ) { $trigType = $trigger{$key}; if ( $trigType == $scheduler->TASK_TIME_TRIGGER_ON +CE ) { print "\t\t$key=ONCE\n"; } elsif ( $trigType == $scheduler->TASK_TIME_TRIGGER +_DAILY ) { print "\t\t$key=DAILY\n"; } elsif ( $trigType == $scheduler->TASK_TIME_TRIGGER +_WEEKLY ) { print "\t\t$key=WEEKLY\n"; } elsif ( $trigType == $scheduler->TASK_TIME_TRIGGER +_MONTHLYDATE ) { print "\t\t$key=MONTHLY_DATE\n"; } elsif ( $trigType == $scheduler->TASK_TIME_TRIGGER +_MONTHLYDOW ) { print "\t\t$key=MONTHLY_DOW\n"; } elsif ( $trigType == $scheduler->TASK_EVENT_TRIGGE +R_ON_IDLE ) { print "\t\t$key=ON_IDLE\n"; } elsif ( $trigType == $scheduler->TASK_EVENT_TRIGGE +R_AT_SYSTEMSTART ) { print "\t\t$key=AT_SYSTEMSTART\n"; } elsif ( $trigType == $scheduler->TASK_EVENT_TRIGGE +R_AT_LOGON ) { print "\t\t$key=AT_LOGON\n"; } else { print "\t\t$key=".$trigger{$key}."\n"; } } else { print "\t\t$key=".$trigger{$key}."\n"; } } } } } $scheduler->End(); Command Line: ************* perl -w sched.pl twjimmywang Sample Output: ************** ==>NetLinkMonitor.job [NetLinkMonitor] APname:D:\MRTG\NetLinkMonitor\NetUp.exe WorkDir:D:\MRTG\NetLinkMonitor Account:TW01\adm ExitCode:0 Status:ready Flags:192 Trigger 0: MinutesInterval=0 Flags=0 StartMinute=0 EndMonth=0 BeginDay=29 RandomMinutesInterval=0 BeginMonth=4 TriggerType=AT_SYSTEMSTART EndYear=0 StartHour=0 MinutesDuration=0 BeginYear=2002 EndDay=0 ==>Mrtg.job [Mrtg] APname:D:\MRTG\CFG\Mrtg.bat WorkDir:D:\MRTG\CFG Account:TW01\adm ExitCode:0 Status:ready Flags:192 Trigger 0: MinutesInterval=0 Flags=0 StartMinute=0 EndMonth=0 BeginDay=14 RandomMinutesInterval=0 BeginMonth=3 TriggerType=AT_SYSTEMSTART EndYear=0 StartHour=0 MinutesDuration=0 BeginYear=2002 EndDay=0

In reply to Re: Win32 Task Scheduler Monitor by Anonymous Monk
in thread Win32 Task Scheduler Monitor by LovelyGreeting

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others studying the Monastery: (3)
    As of 2014-09-18 04:15 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (108 votes), past polls