Saturday, 10 December 2016

Run task scheduler in command line

schtasks is used to create/run tasks in command line without the need to open "Task scheduler".

I've tried query and run parameters but not yet for create.

It is required to provide the task name including the folder that task is created in.

To query if a task exists
 >schtasks /query /tn "thelog"  
 ERROR: The system cannot find the file specified.  
 >schtasks /query /tn "Microsoft\thelog"  
 Folder: Microsoft  
 TaskName                 Next Run Time     Status  
 ======================================== ====================== ===============  
 thelog                  N/A          Ready  
 >schtasks /query /tn "Microsoft\the special log"  
 Folder: Microsoft  
 TaskName                 Next Run Time     Status  
 ======================================== ====================== ===============  
 the special log             N/A          Ready  

To run the task
 >schtasks /run /tn "Microsoft\thelog"  
 SUCCESS: Attempted to run the scheduled task "Microsoft\thelog".  
 >schtasks /run /tn "Microsoft\the special log"  
 SUCCESS: Attempted to run the scheduled task "Microsoft\the special log".  

It is needed to run tasks in elevated command prompt though.

No comments:

Post a Comment