Jump to content
Sign in to follow this  

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.



Edited by mindclutter54

Share this post

Link to post
Share on other sites

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")
$rootFolder = $oService.GetFolder("\")
$oTasks = $rootFolder.GetTasks(0)
$iNum = $oTasks.Count

    If $iNum = 0 Then
        ConsoleWrite("No Tasks Found" & @CRLF)
        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"
                ConsoleWrite("For task " & $sTask.Name & ", status is: " & $sState & " " & $sTask.LastRunTime & @CRLF)

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
  • Like 1

√-1 2^3 ∑ π, and it was delicious!

How to get your question answered on this forum!

Share this post

Link to post
Share on other sites

Thank you very much, works perfectly!  I can't believe after so many years that I had never heard of AutoIt until a week or two ago.  I've barely scratched the surface and I love this program.

Share this post

Link to post
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
Sign in to follow this