Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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)

share|improve this question
up vote 1 down vote accepted

Try the following:

Taskkill /IM program.exe /FI "STATUS eq RUNNING" /F
share|improve this answer
    
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

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.

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

You must log in to answer this question.

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