Sign in to follow this  
Followers 0
mindclutter54

Retrieve Task Scheduler History

4 posts in this topic

#1 ·  Posted (edited)

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

Share this post


Link to post
Share on other sites



#2 ·  Posted (edited)

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
1 person likes this

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

Share this post


Link to post
Share on other sites

#3 ·  Posted

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

#4 ·  Posted

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


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

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  
Followers 0