Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make a .batch file to start/stop a program?

Tags:

batch-file

I need a batch (.bat) file that opens a program if it's not open, and stops the program if it is open. I have a game where when the launcher is closed, it stays open in the background. And I have to end it with task manager or else I can't launch it because steam doesn't like it when an app is open two times (it doesn't allow it), so I would like a batch file that does this for me, then bind it to a macro.

like image 647
MPenate Avatar asked Jun 28 '26 06:06

MPenate


2 Answers

To check if your programm is running : (Here an example with notepad.exe)

@echo off
Set "MyProcess=Notepad.exe"

tasklist | find /i "%MyProcess%">nul  && echo %MyProcess% Is running || echo %MyProcess% Is not running

So you can do like that :

@echo off
Set "MyProcess=Notepad.exe"

tasklist | find /i "%MyProcess%">nul  && Taskkill /F/IM  "%MyProcess%" || start "%MyProcess%"
like image 115
SachaDee Avatar answered Jun 30 '26 11:06

SachaDee


This is another way to do it:

@echo off
tasklist /fi "imagename eq Launcher.exe" |find "." > nul && taskkill /f /im "Launcher.exe" & goto :EOF
tasklist /fi "imagename eq Launcher.exe" |find "." > nul || start "" steam://rungameid/243870 & goto :EOF
like image 29
foxidrive Avatar answered Jun 30 '26 10:06

foxidrive



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!