I am new to batch coding and I am having an issue where whenever I select an option, it goes to 1 (which is :MEMBERS) even if I enter 2 or 3. I am unsure why this is happening.
#echo off
cls
color A
:MENU
cls
echo ===============================
echo Mavast Client v0.01
echo ===============================
echo Enter a number from the list and hit enter
echo to run that program.
echo 1. Members
echo 2. Support us
echo 3. Exit
set /p var= Run:
if %var%=="1" goto MEMBERS
if %var%=="2" goto SUPPORT
if %var%=="3" goto EXIT
:MEMBERS
cls
echo Owner/Rifler = C0MpL3T3
echo Admin/Stratcaller = TDGR (The Dutch Grim Reaper)
echo Awper = NONE
echo Lurker = NONE
echo Entry Fragger = NONE
echo press any key to continue
timeout -1 > NUL
goto MENU
:SUPPORT
cls
echo Support us by donating BitCoins or skins
echo to donate skins, just trade them to TDGR or C0MpL3T3.
echo to donate bitcoins, send any amount you want to this address:
echo 1DSRHe7L842MZjwTWYPzgGzbsZ8zU97w9g
echo thank you!
echo press any key to continue
timeout -1 > NUL
goto MENU
:EXIT
cls
exit
try with
if "%var%"=="1" goto MEMBERS
if "%var%"=="2" goto SUPPORT
if "%var%"=="3" goto EXIT
Quotes are also compared in IF conditions.
Related
I am trying to make a quick program in Batch that asks for user input, but when i get to the input part, the script exits with error:
The syntax of the command is incorrect.
This is my code:
#echo off
color 0a
title WinDoS/PoD- 0.1
echo Automatic DoS/PoD Tool
echo Select what you want to do.
echo 1. Attack
echo 2. Instructions
echo 3. IP Getter
echo 4. IP Searcher
echo 5. Exit
set /p userchoice=
if %userchoice% == 1
goto attack
if %userchoice% == 2
goto instructions
if %userchoice% == 3
goto getter
if %userchoice% == 4
goto searcher
if %userchoice% == 5
exit
:searcher
arp -a
pause
:attack
echo Enter IP adress to attack
set /p address=
goto sequence
:sequence
ping %address% -l 65500 -w 1 -n 1
goto sequence
:instructions
echo WinDoS/PoD Instructions
echo WinDoS/PoD is a program that allows you to perform Denial Of Service (DoS) attacks using a method known as Ping Of Death (PoD)
echo Press 1 on the home menu to enter the attacker program.
echo Input an ip address to DoS
echo If you don't know the IP address to a site, use the built in getter.
echo If you want to view all available network targets, use the built in searcher.
pause
:getter
echo Website (full link):
set /p %website%=
tracert %website%
pause
What is wrong with the syntax?
You're using the wrong command for choosing a known list item, you should be using choice, not set.
Here's an example using your provided information as its basis:
#Echo Off
Color 0A
Title WinDoS/PoD- 0.1
:Menu
Echo(
Echo Automatic DoS/PoD Tool
Echo(
Echo Home Menu
Echo(
Echo 1. Attack
Echo 2. Instructions
Echo 3. IP Getter
Echo 4. IP Searcher
Echo 5. Exit
Echo(
%__AppDir__%choice.exe /C 12345 /N /M "Select a Home Menu item number>"
If ErrorLevel 5 GoTo :EOF
If ErrorLevel 4 GoTo Searcher
If ErrorLevel 3 GoTo Getter
If ErrorLevel 2 GoTo Instructions
:Attack
ClS
Set /P "address=Enter IP address to attack> "
:Sequence
%__AppDir__%ping.exe %address% -l 65500 -w 1 -n 1
GoTo Sequence
:Instructions
ClS
Echo WinDoS/PoD Instructions
Echo(
Echo This program allows you to perform Denial Of Service (DoS) attacks,
Echo using a method known as Ping Of Death (PoD).
Echo(
Echo Press 1 on the Home Menu to begin the Attack program.
Echo Input an IP address to DoS
Echo If you don't know the IP address for a site, use the built-in Getter.
Echo If you want to view all available network targets, use the built-in Searcher.
Echo(
Pause
GoTo Menu
:Getter
ClS
Set /P "website=Website (full link)> "
%__AppDir__%tracert.exe %website%
Pause
GoTo Menu
:Searcher
ClS
%__AppDir__%arp.exe -a
Pause
GoTo Menu
Please note, that I have not looked at the usage of any of your commands, I have offered only improvements to the layout and functionality.
I'm trying to echo a variable into an autoexec.cfg file but I'm having some trouble with echoing a string and a variable to a file simultaneously.
I've tried putting quotes around the echo statement like
echo "sv_maxplayers %answer%">%location%
and, while it echos the string correctly, it includes the quotations marks.
("sv_maxplayers 4")
My script is currently
#ECHO OFF
set location=".\Risk of Rain 2_Data\Config\autoexec.cfg"
set /p answer="Please enter a number 1-16:"
if %answer% GTR 0 (
if %answer% LSS 17 (
goto set
)
)
echo Invalid argument.
goto exit
:set
echo sv_maxplayers %answer%>%location%
echo Done!
goto exit
:exit
pause
exit
Running that returns
Please enter a number 1-16:4
sv_maxplayers
Done!
Press any key to continue . . .
in the console and clears autoexec.cfg.
It should output as
sv_maxplayers 4
Any idea what I'm doing wrong?
Found the solution! I was missing some spaces.
echo sv_maxplayers %answer%>%location%
needs to be
echo sv_maxplayers %answer% > %location%
#echo off
setlocal EnableDelayedExpansion
color b
goto play
:play
cls
set name2= OoggieBoogie
echo Hello, My name is !name2!^^! I'm an AI. I'm here to help with your lazy
Butt :D^^!
timeout /t 3 >null
echo!name2!: May I Have Your Have Your Name Please? :)
color c
echo (Pssst^^! Want to cut the Bullshit and go straight in? Select "Express" please!)
timeout /t 2 >null
echo A. My name is
echo B. Express
set /p input=
if !input! equ B goto Writing2
cls
echo!name2!: Hello !name!, Shall we continue now?
echo 1.Yes :D
echo 2.No -_-" ..
set /p input=!name!:
if !input! equ 1 goto Writing
if !input! equ Yes goto Writing
if !input! equ 2 exit
if !input! equ No exit
:Writing2
echo Okay.. Whatever you want Damn.. I was trying to be nice ^^!
echo Anyway. Inatiating EXPRESS Route----->
goto Writing
Hello!
What I am trying to do here is skipping all the steps and go straight to "Writting2" if typed Express.
I am almost done with this fun program but I can't figure out a good way skip all the steps.
When I type "Express or select 'B'
it crashes.
but If I write a name the program works as usual!
Thanks in Advance!
Sorry in Advance if I did something wrong in the community.
This is a way you can do what you want:
#echo off
color b
goto play
:play
cls
set name2= OoggieBoogie
echo Hello, My name is %name2% I'm an AI. I'm here to help with your lazy
::echo Butt :D^^!
timeout /t 3 >nul
echo %name2%: May I Have Your Have Your Name Please? :)
color c
echo (Pssst^^! Want to cut the Bullshit and go straight in? Select "Express" please!)
timeout /t 2 >nul
echo A. My name is
echo B. Express
choice /c:AB>NUL
if errorlevel 2 goto Writing2
set /p "name=Enter your name: "
:Writing
cls
echo %name2%: Hello %name%, Shall we continue now?
echo 1.Yes :D
echo 2.No -_-" ..
choice /c:1Y2N>NUL
if errorlevel 4 goto exit
if errorlevel 3 goto exit
if errorlevel 2 goto Writing
if errorlevel 1 goto Writing
:Writing2
echo Okay.. Whatever you want Damn.. I was trying to be nice ^^!
echo Anyway. Inatiating EXPRESS Route-----^>
goto Writing
:exit
exit /b
Remember: Variables can be accessed by %variable_name% and you can set them by set "variable_name=variable_value" as #Compo mentioned above.
It is better to use choice /c option in your future batchfiles. A disadvantage of this option is that you cannot enter a string with more than 1 character, but it does it's own errorhandling, so you don't have to deal with invalid responses. Also, when you write
echo Anyway. Initiating EXPRESS Route----->
> symbol causes problems as it is a redirection character and should be escaped:
echo Anyway. Initiating EXPRESS Route-----^>
My batch file skips specific loops and just does certain loops (it only does the first three loops and ignores the rest).
I tried rewriting the batch file, incorporating the new code into an old existing batch file I wrote, but I can't get it working.
echo 1. Login
echo 2. Exit
echo.
set /P M = Command :
IF M == 1 GOTO 1
:1
cls
echo Login
echo.
Set Pass1 = MCTh3sn3r
Set /P Pass = Enter Password :
IF Pass == %Pass1% GOTO 2
:2
cls
echo.
echo Login Successful GOTO 4
:3
cls
echo.
echo Incorrect Password
:4
echo.
echo 1. Shutdown (S)
echo 2. Reboot (R)
echo 3. Logoff (L)
echo 4. Task Manager (TM)
echo 5. Command Prompt (CP)
echo 6. File Locker (FL)
echo. Set /P Choice = Command :
IF Choice == "S" GOTO 5
IF Choice == "R" GOTO 6
IF Choice == "L" GOTO 7
IF Choice == "TM" GOTO 8
IF Choice == "CP" GOTO 9
IF Choice == "FL" GOTO 10
:5
cls
echo.
echo System will now shutdown
Timeout /t 5
Shutdown /s
GOTO End
:6
cls
echo.
echo System will now reboot
timeout /t 5
Shutdown /r
GOTO End
:7
cls
echo.
echo System will now logoff
timeout /t 5
Logoff
GOTO End
:8
gpupdate /force
gpupdate /force
gpupdate /force
gpupdate /force
start taskmgr
GOTO End
:9
gpupdate /force
gpupdate /force
gpupdate /force
gpupdate /force
start cmd
GOTO End
:10
(
if EXIST "PrivateFolder" goto
11
if NOT EXIST Locker goto 12
:13
echo Are you sure you want to
lock the folder (Y/N) ?
set /p Choice = Command :
IF Choice == "Y" goto 14
IF Choice == "y" goto 14
IF Choice == "N" goto 15
IF Choice == "n" goto 15
echo Invalid Choice goto 13
:16
ren Locker "PrivateFolder"
attrib +h + s "PrivateFolder"
echo Folder Locked GOTO End
:11
echo Enter password to unlock
file :
set /p Pass = Password :
IF NOT %Pass% == MCTh3sn3r goto
17
attrib -h -s "PrivateFolder"
ren "PrivateFolder" Locker
echo File locked successfully.
GOTO End
:17
echo Invalid password.
GOTO End
:12
md Locker
echo Locker created
successfully.
GOTO End
)
:End
Exit
Well lets start at the TOP.
This set of code has three things wrong with it.
Do not leave a space between your variable names and variable assignments.
When you need to use a variable you need to surround it with percent symbols.
Your GOTO command will GOTO label 1 regardless of the variable M equaling 1.
.
echo 1. Login
echo 2. Exit
echo.
set /P M = Command :
IF M == 1 GOTO 1
:1
This code should really look something like this.
echo 1. Login
echo 2. Exit
echo.
set /P M=Command :
IF "%M%"=="1" (
GOTO 1
) else (
GOTO END
)
:1
You make the same mistakes in the next set of code. Not sure why you chose to use the percent symbols for one variable but not the other. Again, you need to close up the spaces, use percent symbols for all your variables and your GOTO will go to the label 2 regardless so you need some other code to branch to.
cls
echo Login
echo.
Set Pass1 = MCTh3sn3r
Set /P Pass = Enter Password :
IF Pass == %Pass1% GOTO 2
:2
So again, using my best coding practices I would code it like this.
:1
cls
echo Login
echo.
Set Pass1=MCTh3sn3r
Set /P Pass=Enter Password :
IF "%Pass%"=="%Pass1%" (
GOTO 2
) else (
Echo Wrong Password
Pause
GOTO 1
)
Just going to keep repeating myself. Same problems. Close up the spaces and use percent symbols with your variables. Might want to throw in a case insensitive check for their choices on this one. Not sure how you thought their answers were ever going to match here. You have quotes surrounding one side of your comparison but not the other. Not even going to correct this code you should understand by now what you are doing wrong.
echo. Set /P Choice = Command :
IF Choice == "S" GOTO 5
IF Choice == "R" GOTO 6
IF Choice == "L" GOTO 7
IF Choice == "TM" GOTO 8
IF Choice == "CP" GOTO 9
IF Choice == "FL" GOTO 10
No clue why you are using parentheses here.
:10
(
And here.
)
:End
Exit
This one is dead obvious. You can't have your label on another line.
if EXIST "PrivateFolder" goto
11
And here again. Close up the spaces. Put quotes on both sides of your comparisons. Use percent symbols to reference a variable. And read the HELP for the IF command. Use the /I option!
:13
echo Are you sure you want to
lock the folder (Y/N) ?
set /p Choice = Command :
IF Choice == "Y" goto 14
IF Choice == "y" goto 14
IF Choice == "N" goto 15
IF Choice == "n" goto 15
echo Invalid Choice goto 13
While we are here I would advise that if you are going to keep using the same variable over and over and over again that you clear out the variable before you ask the question. Make this change above.
set "Choice="
set /p Choice=Command :
Couple of problems here. The word file: is on its own line. The number 17 is on its own line. You finally realized that you needed to use percent symbols for you variables but the variable %Pass% is not the same as the variable %Pass %. Close up the spaces and use quotes.
echo Enter password to unlock
file :
set /p Pass = Password :
IF NOT %Pass% == MCTh3sn3r goto
17
So I'm making a game based on making decisions using notepad ++ and batch. I'm new to this and I have no idea what the problem is here.
:start
;startup
cls
echo Wine or Cheese?
echo.
echo 1. Wine
echo 2. Cheese
echo 3. Exit
echo.
set /p input0=Enter:
if %input0% equ 1 goto winestart
if %input0% equ 2 goto cheese
if %input0% equ 3 goto exit
When I select winestart or 1, it goes to winestart for a splitsecond then crashes, with the error message: 1 was unexpected at this time.
Winestart looks like this:
:winestart
cls
echo You are alone. You have a bottle of wine and the clothes you are wearing.
echo What kind of wine do you have?
echo.
echo 1. Red Wine
echo 2. White Wine
set p/ input7=Enter:
if %input7% equ 1 goto redwine
if %input7% equ 2 goto whitewine
/p indicates that the variable is simply set by user input. –
SET
:winestart
cls
echo You are alone. You have a bottle of wine and the clothes you are wearing.
echo What kind of wine do you have?
echo.
echo 1. Red Wine
echo 2. White Wine
set /p input7=Enter:
if %input7% equ 1 goto redwine
if %input7% equ 2 goto whitewine
[Edit: Correct cure, but no explanation of why the error message appears]
Since input7 is not entered, the if statement is interpreted as
if equ 1 goto redwine
cmd expects if something equ anotherthing dosomething so it sees 1 as the comparison-operator. This is not one of the operators it recognises, so it responds that the 1 is unexpected.
A better form of this is
if /i "%input7%" equ "1" goto redwine
where the /i forces a case-insensitive comparison and "quoting the arguments" preserves the syntax requirement where the user enters nothing or a string containing spaces (you have no control over the user's response.)