Chain trigger in Task Scheduler in Windows
I scheduled some tasks in Windows task scheduler. I installed a third party tool called Bmail that added a task that sends email from the task scheduler ind开发者_JAVA技巧ependently. It can be triggered at a given time. Does any one know how to set this up so that Bmail task sends emails when the original tasks are run? How do I link two different tasks in task scheduler and have one trigger the other?
Sorry if this is considered resurection of an old thread. But i wanted answer on this myself and came here first.
You can have them daisy chained. After the first task, schedule the 2nd task to trigger on the event created when the first task completes. It's all explained a bit messy here, https://blogs.msdn.microsoft.com/davethompson/2011/10/25/running-a-scheduled-task-after-another/
By adding this trigger, and firing the Ping Event, the Pong Task Fires immediately after the Ping is complete. It is now a simple case of reusing this XPath replacing the Task Name, \Ping here, with the task to run after:
*[EventData[@Name='TaskSuccessEvent'][Data[@Name='TaskName']='\Ping']]
If you want even more control, you can do as one of the commentators done in the blog linked above.
I've gone further by adding the condition "executing a task only if the previous was completed with the exit code 0".
In order to do that, the "Action completed" event is better than the "task completed" one. The Event Data element of this "Action completed" event contains one more child element with the name "ResultCode" which is exactly what we are looking for !
So the xPath is : *[EventData[@Name='ActionSuccess'][Data[@Name='TaskName']='Ping'][Data[@Name='ResultCode']='0']]
I will update this post more when i've got it to work myself.
You could write a script to emulate what the Bmail task is doing (e.g. Run exe, etc), then change the Bmail task to run that script you just wrote.
From there change the original task to call the same script, this way, if Bmail changes something on how they run, you could update both tasks but simply changing the script.
精彩评论