How to determine what file is scheduled to run with SchTasks.exe in batch?

1

For a given task I need to determine what file it is trying to run with a batch code. Currently I use schtasks /query /TN ITCMD-CHAT-NOTIF | find "Ready" to determine if the task is active, but I see no way to determine what file it is executing. Is it possible?

Mark Deven

Posted 2018-09-28T17:30:52.407

Reputation: 1 101

If you add /v to the run string (schtasks /query /v /TN ITCMD-CHAT-NOTIF), one of the fields contains the schedule string, though it is limited to 50 characters. – AFH – 2018-09-28T17:56:14.020

Add a /v and remove the pipe with find and instead pipe it to a file, then please click edit above and add the result, so we can see more of what's going on. – K7AAY – 2018-09-28T17:56:28.113

Answers

0

To find the full path of the file being run, you can use the /XML switch and FIND "<Command>".

This gives you the XML file you would get if you exported the task, so you can't get both the Status and the Command fields using this command. Instead, you could create a batch file that will run both commands.

task_status.bat:

schtasks /query /TN %1 | find "Ready"
schtasks /query /TN %1 /XML | find "<Command>"

You can then run task_status.bat ITCMD-CHAT-NOTIF to get both fields of the task.

Worthwelle

Posted 2018-09-28T17:30:52.407

Reputation: 3 556