This topic has been locked
Out Of Bubblegum (Banned) Aug 11, 2019 @ 7:23pm
Starting a program with a batch file?
I use Windows 10 64bit. I would like to make a bat file that only runs the program if Steam is already running.
Here is my problem. Fallout 4 gets a lot of unneeded updates that breaks the mods you have installed. You can prevent the updates by putting Steam into the offline mode first. Or prevent Steam doing the updates by running Fallout 4 from a launcher mod. Steam still needs to be running. The mod is not a pirate thing.
I prefer to use the launcher program. But, sometimes I goof and run the launcher before Steam is running. Then Fallout 4 resets my graphics options back to default values for some reason.
I would like a bat file to run the launcher that first checks if Steam is running. It will exit if Steam is not running instead of running the launcher.
Once upon a time I could figure this out. Can someone help out a mushy brained old fart with the code for this? Thanks.
< >
Showing 1-11 of 11 comments
_I_ Aug 11, 2019 @ 7:34pm 
make a shortcut for the exe, or copy the game from steams library and add it as a non steam game

the games exe or launcher will check for steam running first
Out Of Bubblegum (Banned) Aug 11, 2019 @ 7:41pm 
The Fallout 4 exe itself is the one that checks for Steam running. Because it is a Steam only game. That is how the Steam DRM works. It will auto launch Steam before continuing. But that is too late. Fallout 4 just reset my graphics settings for some reason. And it will apply any updates it sees.
_I_ Aug 11, 2019 @ 9:44pm 
if you copy the game to another location, steam will not update it
from x:\...\steam\steamapps\common\gamename
to x:\games\gamename
Bad 💀 Motha Aug 12, 2019 @ 7:57am 
Originally posted by _I_:
if you copy the game to another location, steam will not update it
from x:\...\steam\steamapps\common\gamename
to x:\games\gamename
That doesn't always work because the launcher exe may then look for the game exe in the folder steam installed the game into as this type of info is usually dictated by what's listed in the Windows registry and thus may then still fail to launch due the now the game exe doesn't exist at the game install location.

As far as FO4 though, never really had an issue with the updates breaking mods. Update your mods and you shouldn't have an issue. Use 3rd party launcher called Fallout 4 Configuration Tool - By Bilago. Use that to configure your game and other options such as graphics, use it launch the game, as well as check the options to make the game config files read only. This helps incase you ever launch the FO4 launcher from stream, it won't be able to revert your game config files since they are now set to read only. The config tool however still can.
Last edited by Bad 💀 Motha; Aug 12, 2019 @ 7:58am
RGX12 Aug 13, 2019 @ 11:25pm 
@Out of Bubblegum,

If you're still in need of a batch file for your custom Fallout 4 launcher, I'm posting one for you. As a SysAdmin I've had to write scripts for somewhat analogous purposes in the past, so I modified one to suit your objectives. It will check to see if Steam is running, and if it is it will run your custom FO4 launcher; if Steam is not running it will offer to run it for you, then try running your launcher after Steam loads. The script was tested on my Windows 10 x64 system and performs as expected.

Copy the code below, paste it into a text editor, change the two user variables at the top of the script to your full Steam path (in the script this is already set to Steam's standard location on a 64-bit machine) and the full path of the Fallout 4 launcher, and save the file with whatever name you want, making sure to add a '.bat' extension. You can then run the script either from the console or by creating a shortcut to it and double-clicking. There are additional instructions in the form of comments in the script.

Let me know how it works out for you.

Custom game launcher pre-check script

:: Windows batch file :: exec_fo4.bat :: Version 0.03 :: ::================================================================== :: Fallout 4 launcher :: :: Written for Steam user 'Out Of Bubblegum' :: by 'RGX12' :: :: Batch script for checking if Steam is running before running :: a game's (Fallout 4) custom launcher. :: If Steam is running, run the custom launcher. :: If Steam is not running, ask the user if we'd like to run Steam :: and then start the game launcher, or exit the script. :: :: Under the "User Variables" section, set the full path to the :: Steam executable as well as to the Fallout 4 custom launcher :: ::================================================================== @echo off SETLOCAL enabledelayedexpansion color 5f title Fallout 4 Launcher :: =============== :: USER VARIABLES :: =============== :: *** Note: do not use quotes around the file paths :: Full path to Steam executable SET _STEAM=C:\Program Files (x86)\Steam\Steam.exe :: Full path to custom launcher SET _FALLOUT_LAUNCHER=path\to\custom\game\launcher.exe :: Amount of time in seconds to wait after Steam is launched :: before starting the game launcher :: (to allow for Steam modules to fully load in and Steam "housekeeping") :: Feel free to raise or lower this value as needed SET _STEAM_LOAD_DELAY=20 GOTO :main :main set choice_default_delay=10 echo( :: Quick pre-check that variable paths are valid if not exist "%_STEAM%" ( set ErrMsg=%_STEAM% GOTO :Err1 ) if not exist "%_FALLOUT_LAUNCHER%" ( set ErrMsg=%_FALLOUT_LAUNCHER% GOTO :Err1 ) :: Check if Steam is running CALL :check_if_running "%_STEAM%" :: If Steam is already running, we start the Fallout launcher and exit :: Otherwise, we ask if the user wants to start Steam, and after :: a short delay (user definable) we run the Fallout launcher if %ERRORLEVEL% EQU 0 ( echo Steam is already running echo We can start the Fallout 4 launcher echo( echo * Starting "%_FALLOUT_LAUNCHER%"... CALL :exec_target "%_FALLOUT_LAUNCHER%" timeout /t 3 >nul echo "%_FALLOUT_LAUNCHER%" started ) else ( echo Steam is not running! CALL :steam_launch_query if !ERRORLEVEL! EQU 1 ( echo( echo * Starting Steam... CALL :exec_target "%_STEAM%" timeout /t 3 >nul echo Steam started echo( echo * Starting "%_FALLOUT_LAUNCHER%"... timeout /t %_STEAM_LOAD_DELAY% CALL :exec_target "%_FALLOUT_LAUNCHER%" timeout /t 3 >nul echo "%_FALLOUT_LAUNCHER%" started ) ) echo( echo Script "%~nx0" finished echo Exiting. GOTO :end :: ========== :: FUNCTIONS :: ========== :check_if_running <process name> <RetVal: ErrLev> setlocal set TG=%~nx1 tasklist /nh /fi "imagename eq %TG%" | find /i "%TG%" > nul GOTO :eof :exec_target <target file> setlocal start "" "%~1" GOTO :eof :steam_launch_query echo *** Do you want to launch Steam? *** echo ^(if no keypress, Steam will launch in %choice_default_delay% seconds^) choice /C yn /T %choice_default_delay% /D y /M "Press Y for Yes, N to exit script" exit /b %ERRORLEVEL% :: ======= :: ERRORS :: ======= :Err1 echo Error: Path is invalid, check user variables echo [%ErrMsg%] GOTO :end :end endlocal & exit /b
Last edited by RGX12; Aug 13, 2019 @ 11:31pm
Out Of Bubblegum (Banned) Aug 14, 2019 @ 1:56am 
Thank you sir. I will try it.

But ... but ... but .... you used a goto. A GOTO! Oh nose. You are giving me code to blow up my PC. The horror. :(

Kidding of course :steamhappy:
Bad 💀 Motha Aug 14, 2019 @ 1:14pm 
Seriously, just try the launcher I posted, it even allows easy access to many game settings you can't reach from neither the default launcher or ingame settings.
RGX12 Aug 14, 2019 @ 1:33pm 
Originally posted by Out Of Bubblegum:
Thank you sir. I will try it.

But ... but ... but .... you used a goto. A GOTO! Oh nose. You are giving me code to blow up my PC. The horror. :(

Kidding of course :steamhappy:
A whole treatise can be written on this topic, but in a nutshell...
Windows batch isn't like other languages. Unlike most modern high-level languages, in which the use of GOTO is rightfully eschewed and usually can be completely avoided, in batch GOTO is sometimes preferable or even necessary. I always write my batch code to be as modular as possible, and in a number of cases avoiding the GOTO would lead to much code duplication. In this case GOTO is the lesser of two evils. Furthermore, since batch lacks true exception handling, GOTO is almost always used in cases of error checking, which is how it's used in my script.
If you'd like to attempt re-writing the script to eliminate the GOTO's, please be my guest.
Last edited by RGX12; Aug 14, 2019 @ 1:39pm
Out Of Bubblegum (Banned) Aug 14, 2019 @ 10:22pm 
Originally posted by RGX12:
I was just making a joke. I know well that a goto is very useful for simple code like this. I used to make DOS and Unix batch files a long time ago. I like gotos. I know what they teach now for structured code. One operation per routine. Bah. If I am going to do one operation then I am going to put it inline. Right there so I can read it and not have to use a debugger to follow through to a subroutine before I see that one line.
And I like yelling at clouds and chasing kids off my lawn. :steammocking:
Originally posted by RGX12:
@Out of Bubblegum,

If you're still in need of a batch file for your custom Fallout 4 launcher, I'm posting one for you. As a SysAdmin I've had to write scripts for somewhat analogous purposes in the past, so I modified one to suit your objectives. It will check to see if Steam is running, and if it is it will run your custom FO4 launcher; if Steam is not running it will offer to run it for you, then try running your launcher after Steam loads. The script was tested on my Windows 10 x64 system and performs as expected.

Copy the code below, paste it into a text editor, change the two user variables at the top of the script to your full Steam path (in the script this is already set to Steam's standard location on a 64-bit machine) and the full path of the Fallout 4 launcher, and save the file with whatever name you want, making sure to add a '.bat' extension. You can then run the script either from the console or by creating a shortcut to it and double-clicking. There are additional instructions in the form of comments in the script.

Let me know how it works out for you.

Custom game launcher pre-check script
[/code]

That script still works in 2025! But you have to remove the variables' check part. (The "if not exist" paragraphs.)

That helped me setup a custom Split Fiction launcher!

Kudos to you.
Last edited by Erix Tricittey; Mar 23 @ 8:51pm
Charlie Mar 25 @ 7:09pm 
This thread was quite old before the recent post, so we're locking it to prevent confusion.
< >
Showing 1-11 of 11 comments
Per page: 1530 50

Date Posted: Aug 11, 2019 @ 7:23pm
Posts: 11