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?
12 Answers
Using plain MSDOS, you can do:
schtasks /query /TN my-task-name /FO LISTAnd 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