5

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
  • 4
    Do all shortcuts contain something like steam://run/appid or is it just links to the .exe? If second, then there is your answer. – BadSnowflake Mar 22 '14 at 0:24
  • @Assylum exe shortcuts work too – 3ventic Mar 22 '14 at 1:45
  • 3
    @3ventic Not always. Some games have a problem finding the Steam Service when launched from their directory instead of being launched from Steam. That is why I mentioned it. – BadSnowflake Mar 22 '14 at 9:55
  • 1
    @Assylum Oh, I thought you meant steam.exe with "the .exe". Launching games with steam.exe will always work, but as you mentioned, games can't always find Steam and ask you to launch through Steam instead. – 3ventic Mar 22 '14 at 10:06
0

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.

-1

Just make a desktop shortcut for the steam game then copy the link finally add the link to this code.

start "" "(Your Link)"

It works for me.

-1

This is working in registry and .bat file:

start "" "C:\Program Files (x86)\Steam\Steam.exe" steam://rungameid/322330

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.