Search code examples
windowscmdwindows-task-scheduler

How to create task with event trigger in windows Task Scheduler through command prompt?


I have the below code in a batch file, which if double clicked will create a task TimeLogger in task scheduler which will execute start.vbs file on 16:50 on every day from monday to friday

SchTasks /Create /SC WEEKLY /D MON,TUE,WED,THU,FRI /TN "TimeLogger" /TR "%cd%\start.vbs" /ST 16:15

I am doing this via command promt because i want to send it to my peers, who can just double click the file to create this task.

But I need to modify the task so that it will be triggered by an Event (Event it 20225).I am able to create this from task scheduler UI, but how ill i do this from cmd, so i can make it into a batch file? enter image description here


Solution

  • You can try this:

    schtasks /Create ^
      /SC Onevent ^
      /MO "*[Application/EventID=20225]" ^ 
      /EC Application ^
      /TN "TimeLogger" ^
      /TR "start.vbs" ^
      /F
    

    Schtasks documentation