N
N
Nikolai Savelyev2017-10-03 12:30:27
cmd/bat
Nikolai Savelyev, 2017-10-03 12:30:27

How to set up a task in the scheduler?

There is a task in the scheduler - when the system starts, run the program and repeat every 3 hours. In the settings is "Do not start new instances" (Do not start new instance). The action looks like:

C:\Windows\System32\cmd.exe /C start /WAIT /AFFINITY 2 C:\Scripts\Parser.exe

So - the task every 3 hours launches a new instance of the program. I tried to set "Stop the existing instance" in the settings - it still starts a new process, and the old one continues to work.
How can I make only one task run at a time?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Slyzhuk, 2017-10-03
@SLYzhuk

In the first line of the batch file, add:
taskkill /f /im parser.exe

A
Alexander, 2017-10-03
@NeiroNx

run C:\Scripts\Parser.exe instead of cmd

R
res2001, 2017-10-03
@res2001

If this mechanism does not work, then write the simplest batch file that you insert into the task.
The batch file does the following:
1. checks for the presence of a flag file (any empty file, in any available directory), if the file exists, the task is already running, exit.
2. creating a flag file
3. launching parser.exe
4. deleting the flag file The
downside is that there may be situations when there is no task, and the flag file remains not deleted. In such cases, you will have to delete it manually ...
Another option is to check the presence of a running parser.exe process in the batch file, if there is no process, then start it. You can check processes with tasklist /?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question