Abhilodha
Abhilodha

Reputation: 1

I want to run and kill a process with same batch file

I have bitlord I want this program to run when i click a batch file and when i don't want this program to run i want to kill it with same batch file. Can anyone please write the script Thanks a lot for giving your time. I tried it scripting but failed.

Upvotes: 0

Views: 206

Answers (2)

foxidrive
foxidrive

Reputation: 41234

If bitlord is not running then this will launch it
If bitlord is running then this will kill it

Change line 2 and line 3 to set the program name and path.

@echo off
set "program=bitlord.exe"
set "folder=c:\program files\bitlord"
tasklist |find /i "%program%" >nul || start "" "%folder%\%program%" & goto :EOF
tasklist |find /i "%program%" >nul && taskkill /f /im "%program%" & goto :EOF

Upvotes: 1

AcidJunkie
AcidJunkie

Reputation: 1918

Okay. I think i understand your question now:

@echo off
taskkill.exe /f /im notepad.exe
start calc.exe

The magic is to use the start command which starts a new command asynchronous. Meaning, it doesn't wait for the termination.

Upvotes: 0

Related Questions