Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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

1 Answer 1

up vote 0 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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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