Jump to content
LaunchBox Community Forums

Close Steam after a game closes


Nimdok

Recommended Posts

So I've been trying for the past few minutes to figure out how to get Steam to close automatically after I shut down a game that uses it that was loaded through Launchbox. What I've discovered is that, so far, I'm stymied by the fact that games that require Steam to run don't actually RUN, they just call Steam to open and THEN run from within Steam. So what seems like a basic batch file

start /wait "" "gamename.exe"
taskkill.exe /F /IM steam.exe

doesn't ever trigger the second step.

Trying to have the batch file run steam plus the game's Applaunch parameters leads to the situation where STEAM doesn't ever close, so it never triggers the second step.

Having a dedicated batch file to just kill steam set to run after the main application under Additional Apps doesn't seem to do anything, either. Having it run BEFORE the main application, and waiting for the main application to exit, doesn't work; it seems to be ignoring the 'wait' part and trying to close Steam before it even opens.

Any help would be appreciated.

Link to comment
Share on other sites

Not sure I'm following what you want.

Is this what you want?:

- launch steam game from LB where it basically launches the steam shortcut

- game and steam launch

- exit game, steam remains running.

- close steam?? (is this what you are looking to do?)

You can just add the steam game shortcut to LB. Then for that game, you can add an additional app (in the game properties in LB) in the after section enter the command to exit steam, like taskkill.exe /IM steam.exe

 

Edited by ckp
Link to comment
Share on other sites

See, try that. Tell me if it works. Because when I do that, it doesn't DO anything; it's triggering immediately after the main exe fires, so it closes steam before the game can start. If I run it while Steam is already running it just does nothing. If I set it up to run before the main exe but wait for exit, it still does nothing.

Link to comment
Share on other sites

I'm quite sure what I suggested would work. Try it. The way I suggested is not using any batch files. You need to add an "after" command in the additional apps section for the game. That will kill steam after the game is done running. For launching the game, you don't use a batch file, you just launch it with its shortcut info.

Edited by ckp
  • Like 1
Link to comment
Share on other sites

I have. I am. It's not. The batch file I made before will kill steam if I just run it as-is. When I set it to run as an additional app in Launchbox and run the game, the batch file will either A) if set to trigger after the main EXE it will fire off immediately and kill Steam before the game even loads, or B) if I set it to trigger before but wait for exit it will never trigger.

Link to comment
Share on other sites

52 minutes ago, Nimdok said:

I didn't see your edit to your earlier post. Do you mean adding the killtask command directly to the application path listing for the after command?

Yes, forget the batch file for now. Just use the additional apps tab to type in the taskkill command and parameters directky in the fields. Sorry I'm on my phone and mobile now so I cant give exact steps, but thats what Im trying to get you to try. 

Link to comment
Share on other sites

ok, i'm on my computer now. i think i see your problem. i think it's not running the after additional app at all for me because it doesn't know what process it is that it is supposed to run after since i'm using a steam type launch in format steam://rungameid/240360

maybe for you, whatever exe you launch isn't the one that's running when the game actually closes.

i'll have to think about this one. haha

Link to comment
Share on other sites

i'm not sure the best/easiest way to handle this situation, but you could write a super simple autohotkey script that just launches your steam games normally. 

you would turn the .ahk file into .exe and create an emulator in LB for this new exe.

then you would set all your steam games to run with this "emulator" in the games' emulator tab.

your autohotkey exe just needs to accept the value LB will send it that is in your Application path field, so the autohotkey script will just run that path value. 

so, if your autohotkey script was named like steamlauncher.exe , it would always know to only run the 'after' command when steamlauncher.exe closes, so you keep that open until the game exits.

if i can make a little time, i'll try it out.

Link to comment
Share on other sites

Yeah, I really just don't use Steam super-often, so I don't want it running all the time, and yes, I can easily just close it after I'm done playing a Steam game, but it's not... elegant. It's like making sure your ISO files unmount themselves when you're done playing a game, or that a regular program clears itself from the cache by default. It's simple and elegant and doing it makes things feel... clean.

Thank you so much for screwing around with this and seeing if there's a way to make it work, by the way. I have/had no idea what Autohotkey was, and now I'm looking into it.

  • Game On 1
Link to comment
Share on other sites

  • 3 years later...

Did anyone ever figure this out?  I'm trying to use a batch file to kill x360ce.exe after I exit Killer Instinct on my arcade.  If i tell it to run the batch file after the game it launches the batch file right away and kills x360ce right away...If I click run before and wait until exit, nothing happens...

  • Game On 1
Link to comment
Share on other sites

  • 10 months later...

I am having the same issue when launching a game using a steam url. When I use the actual exe file for the game instead it works as expected. 
 

1. Change game from steam url to exe path. 
2. add before additional app to start x360ce.exe

3. Add after additional app to taskkill x360ce.exe. 
 

Edited by joamjoamjoam
  • Game On 1
Link to comment
Share on other sites

I've made a batch file that starts a program, closes steam and  after closing a game, closes the program too. I start the game within launchbox with the batch file (+vba to hide the batch window). 

I have to go to work, after that i can post my codes ?

 

Edit:

Now, this is the code i used. Steam opens automatic, with the original shortcut. After the game closes, it searches the tasks and closes steam. You don´t have to fear anything of "killing" the task, it´s hard to "break" steam. I do it all the time.

create a .txt file, copy the code below and change the red phrases with yours. After that, change ".txt" to ".bat".

@echo off
start "game.exe"
:waittofinish
tasklist /FI "IMAGENAME eq "game.exe"" 2>NUL |find /I /N ""game.exe"">NUL
if "%ERRORLEVEL%"=="0" taskkill /F /IM steam.exe
exit

You can delete the phrase "start game exe" and open that with launchbox as additional, too. Now, i don´t want to see the commando prompt of cmd popping up, so i use a ".vbs" file. Same thing. Create a txt file, copy the code below into that and change it to ".vbs".

set WshShell = WScript.CreateObject("WScript.Shell")
WshShell.Run ""game.bat"",0,True

The game, bat and vbs should be in the same folder. I hide the original game exe and bat file, so it looks much cleaner in the folder. You have to start the .vbs file or with launchbox the game and the vbs file.

For your x360ce.exe, it´s the same. Maybe you could try this one:

@echo off
game.exe
:waittofinish
tasklist /FI "IMAGENAME eq game.exe" 2>NUL |find /I /N "game.exe">NUL
if "%ERRORLEVEL%"=="0" goto waittofinish
taskkill /im x360ce.exe /F
exit

 

It is possible, that the process in the tasks don´t use the name"x360ce.exe" than you have to search by the taskmanager. Rightclick the x360ce process --> show details --> properties. Same by the game, but thats rare.

I am not a pro, i´ve searched and tinkered it myself. So it can be possible, that the code can be optimized.

I hope it helps. Please let me know.

Edited by JacK1518
Link to comment
Share on other sites

  • 1 year later...

I have done this for years with various scrips and approaches. For the longest time I used a script that sends the mouse pointer to the tray area, right click the Steam icon and select Exit from the tray menu. I used this script mainly because it is a completely safe way to close Steam. But the main appeal for me to use LaunchBox and BigBox is to get everything working as seamlessly as possible. So the drawback of this method was that a script opening tray menus wasn't visually appealing. Because of that I switched to force closing Steam (and other launchers as well). I start all my pc games from AutoHotKey scripts which I imported as roms with AutoHotkey.exe as the emulator. I share an example script for the game Rayman Legends:

#NoEnv
#SingleInstance
#NoTrayIcon
SetTitleMatchMode, 3
SendMode Input
SetWorkingDir %A_ScriptDir%\..\..

Run, steam://rungameid/242550
	WinWait, ahk_exe Rayman Legends.exe
	WinWaitClose
		Sleep 9000
	Process, Close, upc.exe
		Sleep 3000
	Process, Close, steam.exe
		Sleep 1000
	Run, %A_WorkingDir%\Games\Windows\CloseTrayApps\SystemTrayRefresh.exe
ExitApp

What the script does:

- First it sets the LaunchBox folder as the working directory

- Then it launches Rayman Legends via a Steam url.

- Waits for the game window to open and then close.

- Because this game opens Steam and Ubisoft Connect upon launching, after the game window has closed it waits 9 seconds before closing Ubisoft Connect to give it some time to finish cloud syncing.

 - It waits another 3 seconds and then closes Steam. (Because in my experience cloud syncing on Steam can take a little more time.)

- Lastly, force closing tray apps leaves "orphan" tray icons that will disappear when you hoover over them with your mouse. But to automate this process I run an app called SystemTrayRefresh which will remove all "orphan" tray icons.

 

Of course there are many other reasons I start my pc games from scripts. For example to fix the LaunchBox / BigBox startup screens if they don't work properly and to toggle HDR on and off for supported games.

*Edit*

If you just want to add a script as an additional app to your game (tick "Automatically Run Before Main Application"), this is all you need:

WinWait, ahk_exe Rayman Legends.exe ; The games' main executable
WinWaitClose
Sleep 12000 ; Adjust to how long it takes for cloud syncing to finish, if you use it at all. (1000 = 1 second)
Process, Close, steam.exe ; The executable of the launcher
ExitApp

 

Edited by Your Friendly A.I Overlord
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...