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

Status
Not open for further replies.

somone playsmc

Reputable
Jan 15, 2015
57
0
4,640
1
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?
 

gardenman

Admirable
Moderator
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"
 

Ralston18

Titan
Moderator

gardenman

Admirable
Moderator
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"
 

Ramb00

Prominent
Dec 20, 2019
5
0
510
0
I know that this post is pretty old but I need something similar, I want to disable ThrottleStop from Task Scheduler while starting another program and enable it after closing the program. I don't really know if the code from gardenman really works because ThrottleStop is still monitoring.
 

Ralston18

Titan
Moderator
Update your post to include full system hardware specs and OS.

When is ThrottleStop being launched? What triggers the launch?

So you are saying that you tried to disable Throttlestop but it continues to run - is that correct?

What exactly did you do or try?

Can you post more detail about what you did.

Post the code you used....

It may be an "apples to oranges" situation.

Normally, I would suggest starting a new thread but the above history is relevant.

And I do wish to keep @gardenman in the loop.
 
Reactions: gardenman
Status
Not open for further replies.

ASK THE COMMUNITY