Jump to content

Retrieve Task Scheduler History


Recommended Posts

Hi everybody,

I'm fairly new to AutoIt, need some help with something.  So I recently wrotea script using OutlookEX that will run a batch file on my PC after receiving an email with a specific subject from a specific email address.  Thing is, I also need to make sure that a different windows task has run AND completed.

I can't simply run the script after the original task as it's possible that the email has already arrived by the time the other task completes, so right now I'm running the script at the beginning of the one that I need to complete.  Any ideas on how to do this?  I've seen several examples for creating/deleting tasks, etc, but nothing that will give me the logs showing that the date/time the task last completed successfully.

If there's already another thread out there with this info, I apologize...I've been searching for several days now to no avail.

Thanks,

mc54

Edited by mindclutter54
Link to comment
Share on other sites

  • Moderators

You could do something like this to check the last time your task ran (works, but no error checking):

Local $oService , $rootFolder, $oTasks, $iNum, $sName, $sState = 0

$oService = ObjCreate("Schedule.Service")
$oService.Connect()
$rootFolder = $oService.GetFolder("\")
$oTasks = $rootFolder.GetTasks(0)
$iNum = $oTasks.Count

    If $iNum = 0 Then
        ConsoleWrite("No Tasks Found" & @CRLF)
    Else
        ConsoleWrite($iNum & " tasks found:" & @CRLF)
            For $sTask in $oTasks
                Switch $sTask.State
                    Case 0
                        $sState = "Unknown"
                    Case 1
                        $sState = "Disabled"
                    Case 2
                        $sState = "Queued"
                    Case 3
                        $sState = "Ready"
                    Case 4
                        $sState = "Running"
                EndSwitch
                ConsoleWrite("For task " & $sTask.Name & ", status is: " & $sState & " " & $sTask.LastRunTime & @CRLF)
            Next
    EndIf

Edit: I just noticed you mentioned successful runs, you could get this with the .LastTaskResult. You could do something like:

If $oTask.LastTaskResult <> 0 Then ...

 

Edited by JLogan3o13

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

  • Moderators

Glad you got your issue resolved. And yes, it is a great language to have in your scripting repository :)

"Profanity is the last vestige of the feeble mind. For the man who cannot express himself forcibly through intellect must do so through shock and awe" - Spencer W. Kimball

How to get your question answered on this forum!

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...