11

I know you can personalize the launch of a game by adding specific commands on Steam. Can you add a command that runs a little .bat script?

6
  • Out of curiosity, what are you trying to accomplish?
    – Powerlord
    Jun 25 '15 at 0:54
  • @Powerlord The little script (i said .bat because there exists a dos version of Steam so I though it was more likely to work, but I can write the script in any language) should update some files, edit them, and copy some test to the clipboard right before the game launches. Jun 25 '15 at 9:51
  • You could do a custom Steam.exe that basically launches your script and after that launches Steam. Should be pretty easy to accomplish
    – BlueWizard
    Jun 25 '15 at 14:01
  • 1
    @JonasDralle That isn't really what I want, since I want the script to be ran just right before the specific game starts, not Steam. I might want to run Steam and play another game for which I don't need the script to be launched. That's why I want the script to be linked to the game, not to Steam. Jun 27 '15 at 10:31
  • You coould scan the active processes of your PC. The program keeps an eye on your machina and as soon as your game.exe is active it automatically activates the script.
    – BlueWizard
    Jun 27 '15 at 10:34
9

No, but you can achieve the same result with a bit of a hack.

Launch arguments aren't related to batch files. You can use a batch file to launch something with launch arguments but not the other way around. However, if you want to launch the game through Steam and make the batch file run before the game, you can use the steps below to achieve that.

  1. Go to the game's installation folder and find the .exe file for the game. Rename it from something like game.exe to game_real.exe, for example.
  2. At the end of your batch file, add a command that runs your executable, obviously replacing game_real.exe with your renamed game's executable:

    start "" game_real.exe

  3. Find a tool that compiles a .bat batch file into a .exe executable. I haven't tested it but you could try this one at your own risk. Use this to compile your batch file. You may want to play around with the settings to make it not visible and whatever else you want.

  4. Rename the resulting executable to the original name of the game's executable, game.exe in this example. Put this in the same folder as your game's executable.

That should be it. The batch file will run in place of the game when launched from Steam, then it will launch the actual game when it completes your desired actions. If the game has an update that changes the game's executable, your script will be replaced with that. Verifying the integrity of the game cache files will also replace your script with the real executable again. If that happens, just repeat these steps, discarding the old renamed game executable.

14
  • 1
    I used this to automatically delete a file that BioShock creates that essentially says, "I'm running and I'll be deleted when I shut down properly but not if I crash". Since the game crashes a ton and the existence of that file at game startup resets all settings (even including key bindings), I made the batch script delete the file before the game started.
    – Keavon
    Jun 25 '15 at 0:12
  • 2
    @James This is not a way to make a shortcut to a game. This is a way to run a batch file before the game starts, as the question asked. It is not possible to make launch arguments on their own run a batch file because those are entirely different things. I am giving the only possible answer that fits his intent. Unless you want me to just say "it's not possible" without suggesting an actual alternative which seems like a very dissatisfactory answer to me. But your downvote on my answer and your upvote on the answer that does exactly that implies you think actual solutions are a bad thing.
    – Keavon
    Jun 25 '15 at 0:15
  • 1
    While this does work, it's not relevant to steam's launch options, which is what this question is about. He may as well just have a bat file that executes commands and launches the game exe and start it through a shortcut. It would be the same effect, but less work required.
    – Elise
    Jun 25 '15 at 0:21
  • 1
    Even if this doesn't exactly answer the question it's still a better solution than telling it's not possible since this answer still fullfills the requirements of the question.
    – Paedow
    Jun 25 '15 at 0:23
  • 1
    @user3501165 If there is an update that changes the game's executable, the executable you created from the batch file will be replaced with the updated one. In that case, you will have to delete the old, renamed game executable, rename the new one, and put the exe batch file back. This will also be necessary if you verify the integrity of the game cache files. It will not be considered a malicious hack, it is absolutely not against any EULA, and it will certainly not get you banned.
    – Keavon
    Jun 25 '15 at 9:58
5

For those Google pilgrims arriving in the future:

'Add a game...' → 'Add a Non-Steam Game' → 'Browse...' → 'C:\Windows\System32\cmd.exe'.

On new shortcut "cmd.exe" → 'Properties':

  • Name: Awesome Game

  • Target: "C:\Windows\System32\cmd.exe" /k C:\Location\Of\File.bat

  • Start In: the path your game lives in, like "C:\Steam\steamapps\common\AwesomeGame"

Obviously, the .bat file should contain something like "start C:\Steam\steamapps\common\AwesomeGame\a_game.exe"

3
  • thx, it works like a charm
    – binball
    May 9 '20 at 7:34
  • thank you kind sir! Lowly Pilgrim passing through, and that looks like it might be the simplest solution aside from what BlueWizard suggested above. I'm kind of surprised/embarrassed that I didn't think of it myself. Only thing is wouldn't that break most of Steam's integration/overlay features? Or would it pick up on the fact the batch launched the target game's executable? For instance, would steam realize I'm actually playing awesomegame and display that on my friends list? Just a thought. Oct 14 '20 at 17:33
  • thinking about it a bit more, if launching the executable directly doesn't trigger whatever steam integration the game has, one could also just do "steam://rungameid/[appid goes here]". Then the only problem is if the game has a multiple choice when launching (As I recall, it will use the default profile instead of asking you to choose. For most games, that's a nonissue.) Oct 14 '20 at 17:51
3

Short answer: No

The Steam launch commands are no different from adding launch commands to the application's shortcut. It depends on each application what they will or won't parse. You can't run any scripts or anything, unless the game itself has such functionality, in which case, it's not relevant to steam launch commands.

There are different ways of executing commands on software launch, one of them being AutoHotkey scripts, which allows automatic command execution when a process is detected.
Another way would be creating a batch file that will execute the command and then run the game executable, although that may not work with all games (mmorpg's with cheat protection specifically). @Keavon's answer explains how to create an executable out of a batch file, so you can run it directly through steam, rather than through a shortcut.

5
  • 2
    This is a good thing for what its worth. It would be too easy to abuse a system that would let you run scripts with out people being aware of them to start up key loggers or url re-directors and the like just because someone launched a steam game.
    – James
    Jun 24 '15 at 23:49
  • Nice idea, this seems less invasive than Keavon's solution, I'll try it. Thanks :) Jun 25 '15 at 9:55
  • @user3501165 Running an AutoHotKey script the entire time your computer is on to detect the launch of a game is a lot more invasive than simply running your script before it launches your game.
    – Keavon
    Jun 25 '15 at 19:39
  • Yeah, I ended up by integrating it in an AutoHotkey script I was already using. I have to use a hotkey to run it, so it's not really automatic as I wanted it to be, but I prefer this instead of risking to trigger any anti-cheat Ban. Thanks :) Jun 27 '15 at 10:39
  • @user3501165 it is possible to set the script up to detect a process being launched and then execute the little bit of code, but it's complicated and probably not worth the hassle, if you don't mind using a hotkey.
    – Elise
    Jun 27 '15 at 12:15
3

YES

  1. Create a shortcut of the steam game;
  2. Right-click the shortcut then go to 'Properties';
  3. Copy the URL;
  4. Go into the batch file and use start (the url without brackets)

For example my .bat file is:

@echo off
start steam://rungameid/730
cd D:\Desktop\csgo_dont_blind_me
start app.exe
exit
1
  • 1
    I don't think that's what they meant by this question. That lets you start the game from a batch environment, but I think they want to do the opposite: run a batch when (and ideally BEFORE) the game launches (from you choosing "play" in Steam). In my case, I'm trying to set it up so a batch can automatically synchronize my game files (i.e. over my home network) for a game that apparently doesn't support Steam Cloud Synchronization. Plus it would be nice to have an automatic backup subroutine in this case since I can't rely on steam to keep my data backed up. Oct 14 '20 at 17:55
2

This is a bit late, but you can issue any OS shell commands by using the keyword %command%. If that keyword is present in the options, it will run whatever you put in the options field on the command-line (cmd.exe on Windows, /bin/sh on mac OS and Linux) and substitute the keyword with the game's executable. You can separate different commands with semicolons, just like on the command-line.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.