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)

2 Answers 2

2

Try the following:

Taskkill /IM program.exe /FI "STATUS eq RUNNING" /F
2
  • 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, 2012 at 22:44
  • 1
    I got it - use the /FI option !!!
    – Thalia
    Oct 1, 2012 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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .