Writing a batch script

Writing a batch script


  • A batch file is basically the bash script for windows.

  • It uses the ".bat" extension.

  • It basically runs a set of shell commands on the terminal.

  • So my friend wanted to record his gameplay but was too lazy to open obs and record every time so he asked me for a solution.

  • My initial thought was a python script but with further research found out that it's easier to make a batch script.

The batch script

  • First we have to turn echo off else each command will be seen in the terminal opened.

  • Then we have give it a title, this is optional but wtever.

  • we then set a label and a variable with the name of he game like so.

@echo off

title obs_starter
set "filename=VALORANT.exe"
  • we will then check if valorant is running and use if else to do what we need
tasklist /FI "IMAGENAME eq %filename%" 2>NUL | findstr /I /L /C:"%filename%"
if %errorlevel% equ 0 (
    start "" "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\OBS Studio\OBS Studio (64bit).lnk" --startrecording -m
    goto end
) else (
    echo The file %filename% is not open.
  • tasklist displays all running processes from which we retrieve the valorant process and if it is open we start obs and goto the end.

  • else we simply echo that it is not open

  • after this we will wait for 5 seconds using the timeout command and then go back to the check flag at the beginning

timeout /t 5 /nobreak
goto check
  • This should run obs and close itself when you start valorant.

Making it invisible

  • One way i found to hide the terminal window that opens is to make it run from a vbscript.

  • This is anothe scripting language developed by microsoft.

  • I dont fully understand the code here but this is it.

Set WshShell = CreateObject("WScript.Shell")
WshShell.Run chr(34) & "C:\Users\Manmohan\Documents\program\batch\obs_start.bat" & Chr(34), 0
Set WshShell = Nothing
  • This will run the bat file without opening the terminal.


  • This was the first time i tried doing anything using batch scripts.

  • right now i am also trying to create a script to check if valorant is running, so that when you close it, it runs this batch process again so that on reopening the game it still opens obs.

  • I am having some trouble with that but i hope fix it soon.

  • we can now just add this to the startup apps and bam you dont even have to think about it.

  • Thank you for reading and ill keep imporving.

Did you find this article valuable?

Support Manmohan P M by becoming a sponsor. Any amount is appreciated!