Solved: Batch File - Changing code based on user imput

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

luckyg141

Thread Starter
Joined
Apr 4, 2010
Messages
4
Basically I'm creating a Team Fortress 2 batch file that I can use as an admin to view demos in wireframe mode to detect wallhackers,

what i want to be able to do is set up a option where a user can type a file name in, which is then used after they hit enter,

for instance,

I choose the start a team fortress demo in wireframe mode,

I am then given the option to type the demos files name,

This file name is then used in the launch option of team fortress 2 and loads up,

I have included my batch file in a .txt format for you too see what I mean, (the bits I require help on is the bits in < >)

Sorry if this is confusing, I'm just a beginner at creating batch files :)
 

Attachments

Joined
Aug 7, 2007
Messages
9,028
Welcome to TSG!

This assumes the Demo files are in the same folder as Steam.exe. If not, change the path for the _SteamDemoPath variable:

Changes I added are in Red. On the dods and dodswire you have the file name test instead of <filename>, but still had the <User Types Filename> indicated, so I replaced it with the file name variable as well.

Code:
@echo off
COLOR F1
title GTFOGaming Admin Demo Playback
[COLOR=Red]Set _SteamPath=C:\Program Files (x86)\Steam
Set _SteamDemoPath=C:\Program Files (x86)\Steam[/COLOR]
:menu
echo.
echo What would you like to do?
echo.
echo Options:
echo.
echo 1.Open Team Fortress 2 Demo
echo 2.Open Team Fortress 2 Demo In Wire Frame Mode
echo 3.Open Day Of Defeat Demo
echo 4.Open Day Of Defeat Demo In Wire Frame Mode
echo 5.Open Counter Strike Demo
echo 6.Open Counter Strike Demo In Wire Frame Mode
echo 7.Quit
echo.

:choicegame
set /P C=Pick A Number And Hit Enter:
[COLOR=Red]If "%C%" GTR "7" goto choicegame
If "%C%" LEQ "0" goto choicegame[/COLOR]
if "%C%"=="7" goto quit
[COLOR=Red]:: Get file name
:_EnterName
set /P _FN=Enter a File Name and hit Enter:
If "%_FN%"=="" Goto Quit
If NOT Exist "%_SteamDemoPath%\%_FN%" Echo Unable to locate "%_SteamDemoPath%\%_FN%"&Goto :_EnterName[/COLOR]
if "%C%"=="6" goto csswire
if "%C%"=="5" goto css
if "%C%"=="4" goto dodswire
if "%C%"=="3" goto dods
if "%C%"=="2" goto tf2wire
if Not "%C%"=="1" goto choicegame

:tf2
start /d "%_SteamPath%" Steam.exe -applaunch 440 +playdemo [COLOR=Red]"%_FN%"[/COLOR] +r_drawothermodels 1
goto menu

:tf2wire
start /d "%_SteamPath%" Steam.exe -applaunch 440 +playdemo [COLOR=Red]"%_FN%"[/COLOR] +r_drawothermodels 2
goto menu

:dods
start /d "%_SteamPath%" Steam.exe -applaunch 300 +playdemo [COLOR=Red]"%_FN%"[/COLOR] +r_drawothermodels 1
goto menu

:dodswire
start /d "%_SteamPath%" Steam.exe -applaunch 300 +playdemo [COLOR=Red]"%_FN%"[/COLOR] +r_drawothermodels 2
goto menu

:css
start /d "%_SteamPath%" Steam.exe -applaunch 240 +playdemo [COLOR=Red]"%_FN%"[/COLOR] +r_drawothermodels 1
goto menu

:csswire
start /d "%_SteamPath%" Steam.exe -applaunch 240 +playdemo [COLOR=Red]"%_FN%" [/COLOR]+r_drawothermodels 2
goto menu

:quit
exit
:end
 

luckyg141

Thread Starter
Joined
Apr 4, 2010
Messages
4
right im back again,

i would like to change
Code:
Set _SteamPath=C:\Program Files (x86)\Steam
Set _SteamDemoPath=C:\Program Files (x86)\Steam
to a registry file, as currently this only works for other admins in my community that have steam installed in the same place

however the reg key,
Code:
HKCU\Software\Valve\Steam\SteamPath
changes based on where a user has steam installed,

I was wondering how i could use this key instead of using what i have currently.
 
Joined
Aug 7, 2007
Messages
9,028
Replace those two lines with this one:
Code:
For /F "Tokens=2* Skip= 2 Delims=" %%I In ('reg query "HKCU\Software\Valve\Steam" /v SteamPath') Do Set _SteamPath=%%J
and replace _SteamDemoPath with _SteamPath
Should end up with this:
(I'm not sure if the line in red is needed. The path in the registry uses forward slashes, but Windows typically uses backslashes. It should work with either, but sometimes doesn't, so that line may be needed)
Code:
@echo off
COLOR F1
title GTFOGaming Admin Demo Playback
For /F "Tokens=2* Skip=2" %%I In ('reg query "HKCU\Software\Valve\Steam" /v SteamPath') Do Set _SteamPath=%%J
[COLOR=Red]Set _SteamPath=%_SteamPath:/=\%[/COLOR]
:menu
echo.
echo What would you like to do?
echo.
echo Options:
echo.
echo 1.Open Team Fortress 2 Demo
echo 2.Open Team Fortress 2 Demo In Wire Frame Mode
echo 3.Open Day Of Defeat Demo
echo 4.Open Day Of Defeat Demo In Wire Frame Mode
echo 5.Open Counter Strike Demo
echo 6.Open Counter Strike Demo In Wire Frame Mode
echo 7.Quit
echo.

:choicegame
set /P C=Pick A Number And Hit Enter:
If "%C%" GTR "7" goto choicegame
If "%C%" LEQ "0" goto choicegame
if "%C%"=="7" goto quit
:: Get file name
:_EnterName
set /P _FN=Enter a File Name and hit Enter:
If "%_FN%"=="" Goto Quit
If NOT Exist "%_SteamPath%\%_FN%" Echo Unable to locate "%_SteamPath%\%_FN%"&Goto :_EnterName
if "%C%"=="6" goto csswire
if "%C%"=="5" goto css
if "%C%"=="4" goto dodswire
if "%C%"=="3" goto dods
if "%C%"=="2" goto tf2wire
if Not "%C%"=="1" goto choicegame

:tf2
start /d "%_SteamPath%" Steam.exe -applaunch 440 +playdemo "%_FN%" +r_drawothermodels 1
goto menu

:tf2wire
start /d "%_SteamPath%" Steam.exe -applaunch 440 +playdemo "%_FN%" +r_drawothermodels 2
goto menu

:dods
start /d "%_SteamPath%" Steam.exe -applaunch 300 +playdemo "%_FN%" +r_drawothermodels 1
goto menu

:dodswire
start /d "%_SteamPath%" Steam.exe -applaunch 300 +playdemo "%_FN%" +r_drawothermodels 2
goto menu

:css
start /d "%_SteamPath%" Steam.exe -applaunch 240 +playdemo "%_FN%" +r_drawothermodels 1
goto menu

:csswire
start /d "%_SteamPath%" Steam.exe -applaunch 240 +playdemo "%_FN%" +r_drawothermodels 2
goto menu

:quit
exit
:end
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top