shin1234
shin1234

Reputation: 217

windows batch file, if else condition to check if task exist

Current I have this set of codes in a TEST.bat

@echo off
echo HELLO
pause

What I want to do is...

1) I play TEST.bat, it shows "HELLO" on a command prompt (Correct) 2) I play again, another windows pop up "HELLO" on a command prompt (correct behavior but.. )

Is it possible to do this

If(cmd.exe is running)
{
 close it
 play TEST.BAT
}

Upvotes: 0

Views: 1671

Answers (1)

Florian Straub
Florian Straub

Reputation: 856

In theory you can just fire the taskkill command regardless if the task is running or not:

taskkill /f /im sometask.exe

If you really need to figure out if a task is running, you can do

tasklist | find "your task's name"

If afterwards %errorlevel% is 1, the task name was not found.

Upvotes: 1

Related Questions