How do I configure schtasks.exe in Windows 2008 to keep a task running all the time?

1

I have a need to keep a task running all the time which calls a batch file that is pinging a host to cause a delay before a secondary batch file is called. I have configured it to run each time the system starts however this does not keep the task running. Is there way to achieve this and if so how?

PeanutsMonkey

Posted 2012-10-02T19:16:01.320

Reputation: 7 780

Why not configure it to run every x minutes/hours? Also, can you elaborate on what it is you're trying to do exactly? Maybe there's a better way of achieving the same result. – Karan – 2012-10-02T19:20:22.547

1

You want to look into setting up a system service if you want a process to run all the time and be restarted if it dies. If you just want to run something periodically, used Scheduled Tasks. You might also wish to share some more about your goal (whatever the secondary batch file does), because this sounds a lot like an XY Problem

– Darth Android – 2012-10-02T19:20:49.193

@Karan - The first batch file pings a host e.g. 127.0.0.1 twice with a delay of 6 seconds and once it completes, it calls a secondary batch file that goes through a sequence of events e.g. copy, move, delete, etc. The intention is that each time a person places a file in a directory, the aforementioned sequence of events kick of automatically. – PeanutsMonkey – 2012-10-02T19:24:02.247

@Darth Android - I did look at setting up a system service however could not find a resource that described how to set up a system service that calls a batch file. First time I ever heard of the use of a XY problem. – PeanutsMonkey – 2012-10-02T19:24:46.270

@PeanutsMonkey In this case, I would recommend asking your "X" question as a new question here if it's not already answered: "How can I execute a batch file every time a user modifies any file inside of a folder?" Using timed batch files seems kludgy, and you might find a better answer. (Quick search shows that it's been answered for linux and OSX, so a question/answer on how to do it with Windows would be a valuable addition to [SU]) – Darth Android – 2012-10-02T19:55:20.177

Answers

3

srvany can be used to run a batch file as a service. It is a Microsoft-created utility. If you're intent on using a Scheduled Task, you'll just have to set it to run every fifteen seconds or something.

Also, I would recommend using the timeout command for your wait. It's cleaner than using ping. Something like:

:JUMP
timeout /t 6
call "<SECOND_BATCH_FILE>"
goto :JUMP

Kasius

Posted 2012-10-02T19:16:01.320

Reputation: 498

Can it be run on Windows 2008 R2? – PeanutsMonkey – 2012-10-02T21:18:28.983

Yes, it can. timeout is packaged in Server 2008, and srvany runs without issues. I've used it on a Server 2008 machine before and had no problems. – Kasius – 2012-10-05T13:50:33.437