How to detect if a specific scheduled task is running?

I've 2 specific scheduled tasks on my windows 2008 Server

  • The first runs once a day
  • The second runs every five minutes.

In the second task, that is basically a php script, I'd like to check if the first task is running and, if yes, to exit / avoid to run.

So the question is: is there a way to check from command line if a specific task is running?

1

2 Answers

Using plain MSDOS, you can do:

schtasks /query /TN my-task-name /FO LIST

And extract the output. As an example I do:

for /F "usebackq tokens=2,*" %%f in (`schtasks /query /TN my-task-name /FO LIST ^| findstr Status`) do set status=%%f %%g
if "%status%" EQU "Running" goto :eof

You can use the Get-ScheduledTask and Get-ScheduledTaskInfo command in PowerShell.

2

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

You Might Also Like