Steam – Batch file to open Steam shortcuts not working

steam

I created a batch file to pick a random file from a folder. This includes steam games as URL shortcuts but the games fail to read Steam and end up crashing because they lack a connection to their DRM.
The code:

@echo off & setlocal
 :: start of main
 :letsago
 rem Set your path here:
 set "workDir=C:\Users\Nader\Desktop\Gaming"
 rem Set the name of the file here:
 set "name=Random.bat"

 set /a "rdm=%random%"

 rem Push to your path.
 pushd "%workDir%"

 rem Count all files in your path. (dir with /b shows only the filenames)
 set /a "counter=0"
 for /f "delims=" %%i in ('dir /b ^|find "."') do call :sub1

 rem This function gives a value from 1 to upper bound of files
 set /a "rdNum=(%rdm%*%counter%/32767)+1"

 rem Start a random file
 set /a "counter=0"
 for /f "delims=" %%i in ('dir /b ^|find "."') do set "fileName=%%i" &call :sub2

 rem Pop back from your path.
 popd "%workDir%"
 echo Closing in 5 seconds...
 ping -n 6 -w 1000 127.0.0.1 > nul
 goto :eof
 :: end of main

 :: start of sub1
 :sub1
 rem For each found file set counter + 1.
 set /a "counter+=1"
 goto :eof
 :: end of sub1

 :: start of sub2
 :sub2
 rem 1st: count again,
 rem 2nd: if counted number equals random number then start the file.
 set /a "counter+=1"
 if %counter%==%rdNum% (start "" "%fileName%" &echo Starting %fileName%)

 goto :eof
 :: end of sub2

Best Answer

I've not used BAT in years so I can't really help with a script, but there is an easier way to do this:

  • Find the Steam Library Folders that you want to randomly launch apps from (include in a list of random folder options?) and scrape the names of all of the files with the extension ".acf" from it. These are Steam's appmanifest files which contain some of the data & settings for installed apps, and have a name format like appmanifest_#.acf where the # is the Steam appid of the app, which is unique for every app and is needed for the next part.

  • When a Steam app is selected to be launched (noticeable to the script because of the appmanifest_ part of the file name) extract the appid from the file name (only the number portion, not the appmanifest_ part, and of course not the extension) and then launch Steam with a command-line argument using something like C:\Program Files (x86)\Steam\Steam.exe -applaunch # where # is the appid to launch.

This will start Steam and have it launch the game for you, so there should be no issues with any games not finding the client.

Related Topic