im currently writing a batch file and i would like to make a toggle menu for choices to execute instead of the common question and answer execution
is there any way to make a list of choices and toggle "run" or "off" for them and hit enter to start
I found a file that seemed to get me in the right direction but i dont know how to make it work with my batch file
the code i found is...
#echo off
set _on=0
:top
cls
if %_on%==0 (set _nlb= &set _nrb= &set _flb=[&set _frb=]) else (set _nlb= [&set _nrb=]&set _flb= &set _frb= )
echo The '_on' flag is currently: %_nlb% On %_nrb% %_flb% Off %_frb%
echo.
echo Press any key to toggle the '_on' flag
pause>nul
if %_on%==0 (set _on=1) else (set _on=0)
goto top
id like it to look like
netusers [run] [off]
netuseradministrator [run] [off]
virus.exe [run] [off]
press enter to initiate selected.
in that type of layout if that makes any sense
use the Choice command. for example
echo 1] Settings
echo 2] Start
echo 3] Quit
choice /c 123 /n
if %errorlevel%==1 goto settings
if %errorlevel%==2 goto start
if %errorlevel%==3 goto quit
there are more parameters for timeout and stuff like that. Look at choice /?
Related
I don't know if any of you guys know anything about batch (I am sure someone does), but in regards to this post, I am trying to create a dumbed down DND Assist (something that you would tell you stats to and that would assist you in completing an action irl faster than rolling dice and doing the math yourself.
Currently I have the random num generator somewhat working (although I would like to improve it)
This version is set to choose a random number between 1 and 20, I would like to figure out a way to have the program notice if you roll a 1 or a 20 (Crit hits / crit fail)
Also I need something later that will show me how to save certain values as variables,
#echo off
:Start
Set /a ans="%RANDOM% %% 20"+1
echo %ans%
pause
goto Start
(In regards to saving variables, when the program is ran, it will tell me that I am missing an operation.)
The coloring portion was just for the hecks of it, if someone can show me a way to streamline that section please tell.
Please use lamens terms, Im still not very good at understanding any of this.
(CURRENT ASSIST PROGRAM PROGRESS)
#echo off
cls
:BEGIN
Echo HI THERE! AND WELCOME TO MY GAME!!
Echo Lets begin by setting your prefered color!
:A
set choice=
set /p choice= RED, WHITE, OR BLUE?!?
if not '%choice%'=='' set '%choice%'=='Red, White, Blue'
if '%choice%'=='RED' goto RED
if '%choice%'=='WHITE' goto WHITE
if '%choice%'=='BLUE' goto BLUE
if '%choice%'=='Red' goto RED
if '%choice%'=='White' goto WHITE
if '%choice%'=='Blue' goto BLUE
if '%choice%'=='red' goto RED
if '%choice%'=='white' goto WHITE
if '%choice%'=='blue' goto BLUE
if '%choice%'=='9' goto 1Bs
echo "%choice%" is not a good color bro, do a different one
goto A
:RED
color 4
goto START SCREEN
:WHITE
color 7
goto START SCREEN
:BLUE
color 1
goto START SCREEN
:START SCREEN
cls
TITLE CHOOSER GAME BOI
Echo ---THE DND GAME---
echo Welcome to the DND game, we will first choose your Attributes
echo Strength (How hard you hit) (STR)
echo Constitution (Your health) (CNST)
echo Knowledge (Better Rolls against Vendors and Questions) (KNLG)
echo Dexterity (Your chances of dodging and Hitting) (DXT)
echo You have a total of 10 points to apply to each Attribute
echo Your points HAVE to equal 10 otherwise you will have to restart
:ATTRSET
set MXPNTS=10
set choice=
set /p STR= STR (1-10)
set choice=
set /p CNST= CNST (1-10)
set CNST=CNST
set choice=
set /p KNLG= KNLG (1-10)
set KNLG=KNLG
set choice=
set /p DXT= DXT (1-10)
set DXT=DXT
set /a ATTRTTL=STR+CNST+KNLG+DXT
echo ATTRTTL
if NOT ATTRTTL=MXPNTS goto ATTRSET
if ATTRTTL=MXPNTS goto testyay
pause
:testyay
pause
I would personally suggest:
#echo off
cls
:begin
echo HI THERE! AND WELCOME TO MY GAME!!
echo Lets begin by setting your preferred color!
:a
set /p choice= RED, WHITE, OR BLUE?!?
if "%choice%" == "" (
echo Please enter something!
cls
goto :A
)
for %%A IN (red white blue) do if /I "%choice%" == "%%A" (call :%%A & goto :start_screen)
if "%choice%" == "9" (goto 1Bs)
echo "%choice%" is not a good color bro, do a different one.
goto :a
:red
color 4
exit /b
:white
color 7
exit /b
:blue
color 1
exit /b
:start_screen
cls
title CHOOSER GAME BOI
echo ---THE DND GAME---
echo Welcome to the DND game, we will first choose your Attributes
echo Strength (How hard you hit) (STR)
echo Constitution (Your health) (CNST)
echo Knowledge (Better Rolls against Vendors and Questions) (KNLG)
echo Dexterity (Your chances of dodging and Hitting) (DXT)
echo You have a total of 10 points to apply to each Attribute
echo Your points HAVE to equal 10 otherwise you will have to restart
:ATTRSET
set "mxpnts=10"
set /p "str=STR (1-10) "
set /p "cnst=CNST (1-10) "
set /p "knlg=KNLG (1-10) "
set /p "dxt=DXT (1-10) "
set /a "attrttl=str+cnst+knlg+dxt"
echo %ATTRTTL%
if not "%attrttl%" == "%mxpnts%" (goto :attrset) else (goto :testyay)
pause
:testyay
pause
Capitalization detected! Successfully removed! As batch is a case insensitive language, uppercase letters would make noise and make reader close the tab with your question and move on - or at least me.
The whole thing about the choice variable you did was not needed. Just a for loop looping through the color words and checking (case insensitive) if the user input was red, white or blue.
I have decided to call subroutines, not goto to them to save some lines - I usually do it to my programs: you had put 3 separate commands goto START SCREEN which could be simplified calling the subroutine (which means goto to it, but then return) and then goto where you want.
Remember: it is not good for your files/folders to contain a space in their name. This can cause quite many misbehaviours. It is just the same in all languages: when you name variables, functions, subroutines or whatever, don't include spaces! I have renamed it to start_screen.
That's all, follow excellent suggestions by Squashman in comments and read the help of some commands in cmd, typing command /? and you should be fine.
I am running the following program ,
#echo off
color 0a
cls
:MENU
echo What do you want to do ?
echo.
echo 1- Flash
echo 2- Wipe
echo 3- Check
echo 4- Go Back
echo.
set /p choice=
if %choice%==1 goto 1
if %choice%==2 goto 2
if %choice%==3 goto 3
if %choice%==4 goto 4
echo Invalid Choice
goto MENU
:1
flash.bat
:2
wipe.bat
:3
check.bat
:4
back.bat
In this program when i press any other key other than 1,2,3,4 it need to show invalid choice. But, its not working.. its shows error "goto command was unexpected at this time".
Please help me guys..When pressing anyother key it need to show invalid choice. Pls help guys...
I suggest, using choice, which does errorhandling on it's own, so you don't have to deal with that. There are many ways (many possible inputs) to break your script when using set /p.
If you want to keep with set /p, at least preset the variable (set /p doesn't set the variable to "empty" when you press ENTER, but lets it unchanged):
set choice=4
set /p choice=
echo %choice%
...
Additional bonus: you have a default action.
My idea was to have it start when the computer boots and then ask me what game do I want to play. That's simple but I want to be able to answer different answers like: Is the input like CS:GO,cs,csgo,counter strike, and so forth and, here's how I tried to do it=
if %game%==1,CS:GO,cs:go,csgo,"Counter Strike","counter strike" goto cs
But as you probably know, it did not work. so the question is how to make it so that "%game%" can be a lot of different things and still goes to the same thing without having to do multiply if %GAME%==...?
and here's the whole code if you want to see it=
#echo off
color a
cls
:start
echo what game do you want to play?
echo 1/"CS:GO"? -"Counter Strike: Global Ofensive"
echo 2/"H&G"? -"Heros & Generals"
echo 3/"P2"? -"Portal 2"
echo 4/"UT"? -"Unturned"
echo 5/"LO"? -"Loadout"
echo 6/"DAB"? -"Double Action Boogaloo"
set /p game=vwhat game?:
if %game%==1,CS:GO,cs:go,csgo,"Counter Strike","counter strike" goto cs
pause
goto start
:start
echo what game do you want to play?
echo 1/"CS:GO"? -"Counter Strike: Global Ofensive"
echo 2/"H&G"? -"Heros & Generals"
echo 3/"P2"? -"Portal 2"
echo 4/"UT"? -"Unturned"
echo 5/"LO"? -"Loadout"
echo 6/"DAB"? -"Double Action Boogaloo"
set /p game=what game?:
echo /1/CS:GO/csgo/Counter Strike/ |find /i "/%game%/">nul && goto cs
rem other games here...
pause
goto start
/i makes the findcase insensitive, so it will find CSGO, CsGo, cSgO,...
&& works as "if previous command (find) was successful, then..."
Now i know how to create what i call tags
for example :startgame
And i know goto :startgame or in some occasions just goto startgame will take you back however
when i am doing if %selector% == r goto :Start_1
it just simply will close the batch file and i have tried with caps and without and without the :.
Now don't just be rude and call me ignorant i know basic batch
This is my start code
:Start_1
echo **************************************************
echo ************App selector by michaelukz************
echo **************************************************
echo **************************************************
echo To select an app press any button.
pause
This is the code i am trying to get to work
:Selected
echo You have selected your file.
echo If you wish to choose another file press R.
echo If you wish to close a program / file press C.
echo If you wish to close press any button.
SET /P"selected=Input letter here: "
if %selector% == r goto :Start_1
if %selector% == R goto :Start_1
if %selector% == c start taskmgr.exe
if %selector% == C start taskmgr.exe
if not timeout /T 3
echo Going to close menu
goto Closemenu
all the rest works except goto start_1.
Please help but don't be ignorrant - i have seen other people on here acting snarky as such.
A few things...
What you are calling tags are usually referred to as labels.
In your code, you are setting a variable called selected in this line SET /P"selected=Input letter here: ", but in your IF statements you are comparing to a variable called selector.
The line if not timeout /T 3 will not work. As #Magoo pointed out in a comment to the question, the syntax of if requires a comparison operator if [not] something compare-op something_else dothis.
take a look at CHOICE command, also you misspelled selector var name in SET /P
#echo off
:Start_1
echo **************************************************
echo ************App selector by michaelukz************
echo **************************************************
echo **************************************************
echo To select an app press any button.
:Selected
echo You have selected your file.
echo If you wish to choose another file press R.
echo If you wish to close a program / file press C.
echo If you wish to close press Q.
choice /C RCQ /N /M "Choose wisely [R,C,Q]" /D Q /T 30
goto action%errorlevel%
:action1
echo option R
goto start_1
goto selected
:action2
echo option C
start taskmgr.exe
goto selected
:action3
echo option Q
goto closemenu
goto Closemenu
What I'm looking for is a batch file line of code that will scan what the user inputs to find key words and direct them in the right place. That way when a trainee has a question he/she could just ask the batch file and it will direct them to the proper menu. Is this possible? if so, How would one go about doing this?
:menu
set /p c=Please type you question:
findstr /m "How to ringout a product on our system?" "%c%"
if %c%=="ringout" (
goto :Ringingout
) Else (
goto :Sorry
)
:Ringingout
cls
echo In order to right something out maksure you do the following:
echo - Log in
echo - click on scan in the bottom left had corner on the tender page
echo - scan items
echo - click continue
Pause
goto :Menu
:Sorry
cls
echo Sorry I don't recognize your question, please re-word it.
pause
goto :Menu
#ECHO OFF
SETLOCAL
SET "keywords=word anotherword someword"
FOR %%k IN (%keywords%) DO set "#%%k="
SET /p query="Please enter your query ? "
FOR %%k IN (%keywords%) DO CALL :analyse %%k
SET #
GOTO :EOF
:analyse
CALL SET "found=%%query:%1=%%"
IF "%found%"=="%query%" GOTO :EOF
SET #%1=FOUND!
GOTO :eof
Here's a general way to do it.
If one of the keywords is entered, the variable #keyword will be set to FOUND! so you can use if defined #keyword to process from there.
It's not protected against destructive user-inputs - that's not what this question is about...
You'd be better off collecting all the questions in a document (like .html) and letting the user search that document for what they need. But if this is just an exercise, you can re-write your logic like so to make your program work:
:menu
set "c="
set /p "c=Please type your question: "
echo %c% | findstr /i /b "ringout" >nul
if errorlevel 1 goto Sorry else goto Ringingout
:Ringingout
and so on.