3

In a command file, startup.cmd, I have something like

start "program.exe"

I would like to do the following:

if running, stop program.exe
start program.exe

I tried

taskkill program.exe

If the process is not running though, I get an error - and I don't want to get errors... Not sure if this is not too violent a kill, either.

How can I stop my program if it is running, before starting it ? (if it starts while another instance of itself is running, results may be unpredictable...)

(Windows)

1

Try the following:

Taskkill /IM program.exe /FI "STATUS eq RUNNING" /F
  • Thank you, I was just finding it - I still get an error when the process is not running... is there anything to find out if the process is running ? – Thalia Oct 1 '12 at 22:44
  • 1
    I got it - use the /FI option !!! – Thalia Oct 1 '12 at 22:48
0

Just keep in mind that bat file should be in C:/ not other drives If so it will not work and give you an Access Denied error. So be careful.

  • I did check for the local drive but thank you for adding this – Thalia Sep 26 '14 at 17:42

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.