How to close and open a program when another program opens and closes respectively

somone playsmc

Jan 15, 2015
Basically, I want a program (rainmeter) to close when I open up League of Legends and rainmeter to open again when League of Legends closes. Is there any way to do this?




I hope Ralston doesn't mind if I post an alternative to powershell. Powershell should work, but it's slightly complicated for non-programmers.

I would try a batch file (no guarantees but it might work). You can use taskkill to close programs out. You can use start to run programs and even have it wait until a process is done before the batch file continues. Here is an example that I wrote and tested. You would need to replace notepad with your game and maybe make other changes for Rainmeter, but it worked in my tests.

Copy/paste the below in notepad and save it as RunGame.bat. Create a shortcut to RunGame.bat and in the shortcut properties choose to Run Minimized (this hides the command prompt window). Tip: Only the 4 lines in bold are required. The rest are just my comments. Remember that if this works to close Notepad out to have Rainmeter re-open.

I did notice one problem. After closing Rainmeter out, the tray icon remains. You can make it disappear by simply moving your mouse over top of it. If you notice multiple Rainmeter icons in the tray then it's likely where you ran this batch file, simply hover the mouse over them.

@echo off
echo Close, Run, And Reopen by gardenman 05/25/2018

REM Close Rainmeter out.
taskkill /f /im Rainmeter.exe /t > NUL

REM Run your game here.
REM Start allows you to run programs.
REM /wait tells the batch file to hold all processes until the game is done.
REM "" is the Title of the command prompt. This is needed in order for quotes to work around the filename.
REM "C:\Windows\notepad.exe" should be replaced with your game.
start /wait "" "C:\Windows\notepad.exe"

REM After the above is closed out, re-run Rainmeter here.
REM Remember to leave the first set of quotes blank as they are not needed.
start "" "C:\Program Files\Rainmeter\Rainmeter.exe"