1

I'm struggling a bit with this. The idea of the script should be:

If program 1 is running Close it then open it If not running Do nothing

This will be used on XP and win7 machines

Here's what I have, but I have no idea how to incorporate the if statements or even if what I have is remotely correct:

tasklist /fi "imagename eq KDS.exe" taskkill /f /im "KDS.exe"  start "" "C:\Path\KDS.exe"
user2022089
  • 39
  • 1
  • 9

1 Answers1

1

I would do the taskkill first, and check its return value to determine whether it succeeded or not. If it did, then restart the process.

taskkill /f /im "kds.exe" && (
    start "" "C:\Path\KDS.exe"
)

Source of inspiration: Killing a process in Batch and reporting on success

Community
  • 1
  • 1
Nate Hekman
  • 6,507
  • 27
  • 30
  • I tried exactly that on a computer where the process wasn't running, and it started it. The idea would be to check if it's running, if it is to restart it. If it's not running, don't try and start the program. – user2022089 Apr 10 '13 at 11:29
  • Hrmph. Sure enough. I've added the `/f` flag and used `/im` instead of `/fi`, and now it returns the error codes I was expecting. – Nate Hekman Apr 10 '13 at 20:29