I'm trying to create an admin "login" on batch and it just closes the cmd - batch-file

I am trying to make an "admin" login and it isn't working.
#echo off
title RPG BETA
color 0b
set /p player=Welcome to Xero, what's your name?:
if %player% == Admin goto admin
:intro
echo Hello %player%!
pause
goto start
:admin
set /p password:What is the admin password?:
if %password% == Insertanypassword goto true
if %password not insertanypassword goto false
:true
cls
echo Welcome, Admin!
set /p af=Would you like to enable admin features?[y/n]:
if %af% == y goto true1
if %af% == n goto start
:true1
cls
set CPU=20
set CPUN=Scorpion
set CPUD=3
set gun=9999999
set gund=9999999
set playerh=9999999
goto fight
:start
cls
echo In the distant future, the world was on the brink of destrucion.
timeout 3 >nul
echo In the midst of the wasteland, a single man, named %player%, will overcome the odds
pause
goto BFight
:BFight
cls
set CPU=20
set CPUN=Scorpion
set CPUD=3
set gun=1
set gund=10
set playerh=20
:Fight
cls
if %CPU% leq 0 goto win
if %playerh% == 0 goto lose
cls
echo You encounter a %CPUN%!
echo %CPUN% Health: %CPU%
echo.
echo Your Health: %playerh%
echo [1]Shoot (%gund% damage) (%gun%)
echo [2]Punch (3 damage)
echo [3]Flee
set /p fp=What do you do?
if %fp% == 1 goto gun
if %fp% == 2 goto punch
if %fp% == 3 goto flee
:gun
cls
if '%gun%'=='0' goto egun
set /a gun = gun - 1
echo You fire at the %CPUN%
timeout 4 >nul
echo It hits!
set /a CPU = CPU - gund
pause
goto cpufightp
:punch
cls
echo You punch the %CPUN%
timeout 4 >nul
echo It hits!
set /a CPU = CPU - 3
pause
goto cpufightp
:egun
echo You have no bullets!
pause
goto Fight
:cpufightp
if %CPU% leq 0 goto win
cls
echo %CPUN% Health: %CPU%
echo.
echo Your Health: %playerh%
pause
cls
goto cpufight
:cpufight
cls
echo The %CPUN% Attacks!
timeout 4 >nul
echo It hits!
set /a playerh = playerh - CPUD
pause
goto fight
:flee
goto losef
:losef
cls echo you have fled
pause
goto suggestion
:lose
cls
echo You died
pause
cls
:win
cls
echo Congradulations, %player%! You win!
pause
cls
:suggestion
set /p suggest=What should I add to Xero?:
echo %player%: %suggest% >> xerosuggest.word
Whenever I type in "Admin" instead of going to the password screen, it just closes cmd, can anyone tell me why? i have experimented with ''s and other commands but I just can't figure it out.

The problem with respect to your specific issue is a typo.
You have:
set /p password:What is the admin password?:
Instead of:
Set /P "password=What is the admin password?: "
The doublequotes are simply good practice, your error was quite clearly that you used a : instead of a =.

Related

Batch file closes after a goto command

Here's the code
#echo off
color 0a
:user_login
set /p username=What is your username?
if %username% == admin (
cls
goto admin_request_password
)
echo Incorrect username please try again.
cls
goto user_login
:admin_request_password
set /p Password=What is your Encryption Key?:
if %Password% == ecca1924889236 (
pause
cls
goto admin_menu
pause
)
echo Incorrect password
pause
cls
goto user_login
:admin_menu
echo Type acct_info for account info.
echo Type site_key for website file manager.
echo type ip_info for your ip info.
echo Type close to close the Net-Sec portal
goto admin_menu_process
:admin_menu_process
set /a choice=Waiting for Request:
if %choice% == acct_info (
cls
goto acct_info ) echo Incorrect term cls goto admin_menu
if %choice% == site_key (
goto site_key )echo Incorrect term
cls
goto admin_menu
if %choice% == ip_info (
goto ip_info ) echo Incorrect term
cls
goto admin_menu
if %choice% == close (
goto close ) echo Incorrect term
cls
goto admin_menu
:ip_info
ipconfig
pause
cls
goto admin_menu
:acct_info
echo Your username is: admin
echo your password is: ecca1924889236
pause
cls
goto admin_menu
:site_info
The username is: net-sec
The password is: netsec127
pause
cls
goto admin_menu
:close
cls
Suggestions:
Do not set a variable to %username% as that is already an existing system variable.
Enclose both strings with double quotes in a string comparison.
Use the choice command when you have a known set of choices.
Try not to include unnecessary labels.
Here is a rewrite of your code to hopefully help you in your scripting exploits:
#Echo Off
Color 0A
:getName
ClS
Set/P "uname=What is your username? "
If /I Not "%uname%"=="admin" (Echo Incorrect username please try again.
>Nul Timeout 3
GoTo getName)
:getPass
ClS
Set/P "password=What is your encryption key? "
If Not "%password%"=="ecca1924889236" (Echo Incorrect password please try again.
>Nul Timeout 3
GoTo getPass)
:menu
ClS
Echo [1] Account information.
Echo [2] Website File Manager.
Echo [3] IP information.
Echo [4] Close the Net-Sec portal.
Choice /C 1234 /M "Enter your request"
If ErrorLevel 4 GoTo close
If ErrorLevel 3 GoTo ip_info
If ErrorLevel 2 GoTo site_info
If ErrorLevel 1 GoTo acct_info
GoTo :EOF
:acct_info
Echo Your username is: admin
Echo your password is: ecca1924889236
Timeout 3
GoTo menu
:site_info
Echo The username is: net-sec
Echo The password is: netsec127
Timeout 3
GoTo menu
:ip_info
IPConfig
Timeout -1
GoTo menu
:close
ClS
Echo Closing...
Timeout 3

Multiple choice questions will respond to anything using simple cmd code when i dont want them to?

I made this code this afternoon and only started to start doing this about a day ago. I can seem to find out why when playing my game I can just press enter on my questions and it will go through to the next level even though I set questions for it.
#echo off
title 'Hospital Nightmare'
color 47
if "%1" neq "" (goto %1)
pause
:Menu
cls
echo '1 Start'
echo '2 Instructions'
echo '3 Exit'
set /p answer='Type the number of your option and press enter'
if %answer%==1 goto 'Start_1'
if %answer%==2 goto 'Instructions'
if %answer%==3 goto 'Exit'
:'Exit'
#echo off
echo Happy Dreams
pause
exit /b
:'Instructions'
#echo off
cls
echo 'Instructions'
echo.
echo Self Explanitory you
echo IDIOT!
pause
goto Menu
:'Start_1'
#echo off
cls
echo You awake in a small room
echo that smells like sterilisation
echo and surgical equiptment.
echo.
echo Even though it's small,
echo many things are inside.
echo this is strange?
echo.
echo Screams echo around you
echo and a noise is coming from
echo around the corner!
echo.
set /p answer='Press 1 to find out what it is!'
if %answer%==1 goto 'Fight_1'
:'Fight_1'
#echo off
cls
echo "YOU, YES YOU THERE! DON'T
echo LOOK AT ME LIKE IM STUPID
echo YOU KNOW WHAT I WANT, NOW
echo FIGHT ME!!"
echo.
echo What is this guy going on
echo about??
echo.
set /p answer='would you like to fight or run?'
if %answer%==Fight goto 'Fight_1'
if %answer%==Run goto 'Run_1'
:'Run_1'
#echo off
cls
echo You escape safely!
:'Fight_1'
#echo off
cls
echo "GOOD LUCK"
echo "YOU'RE GONNA NEED
echo IT!"
echo.
echo You wait for thhe first punch
echo.
set /p answer= Type the number 1 and press enter to continue:
if %answer%==1 goto 'Fight_1_Loop'
:'Fight_1_Loop'
set /a num=%random%
if %num% gtr 4 goto 'Fight_1_Loop'
if %num% lss 1 goto 'Fight_1_Loop'
if %num%==1 goto 'Lose_Fight_1'
if %num%==2 goto 'Win_Fight_1'
if %num%==3 goto 'Win_Fight_1'
if %num%==4 goto 'Win_Fight_1'
:'Lose_Fight_1'
#echo off
cls
echo "FIGHT ME EH? YOU
echo GOT NO CHANCE!"
echo.
echo You are knocked
echo out cold! :'(
pause
goto Menu
:'Win_Fight_1'
#echo off
cls
echo "I WAS ONLY JOKING
echo YOU'RE HUGE MAN
echo LEAVE ME ALONE!"
echo.
set /p answer='Would you like to save?'
if %answer%==Yes goto 'Save'
if %answer%==No goto 'Start_2'
:'Save'
#echo off
cls
echo YOU IDIOT YOU CAN'T SAVE
echo I'M NEW TO THIS AHAHAHA!
:'Start_2'
#echo off
cls
echo That guy was crazy.
echo Now where am I? and what did
echo he want with me?
echo.
echo This place is an old hospital
set /p answer='Before we keep going what's your name?'
if %answer%=="Meerkat" goto 'Hallway'
:'Hallway'
#echo off
cls
echo You turn left to into a
echo hallway to find that it
echo is very long and wide.
echo.
echo LIKE MY D*CK!!!
echo.
echo "Now is not the time to
echo joke narrator."
echo.
echo Ok
echo.
echo Well umm...
echo You turn left...
echo To find...
echo A...
echo F*CK IT! You find
echo a HOBO OCTOPUS!!!
echo.
echo "Dude wtf."
echo.
echo "Ok I'll do it."
echo.
echo YESS! Let the battle begin!
echo.
set /p answer='Will you fight this fight?'
if %answer%==Yes goto 'Fight_2'
if %answer%==No goto 'Scene_1'
:'Scene_1'
#echo off
cls
echo YOU DON'T WANT TO FIGHT
echo AN OCTOPUS?
echo.
echo WHAT ARE YOU? OCTOPUSSY?
pause
goto Menu
:'Fight_2'
#echo off
cls
You need to set the variable to blank as you get the prompt:
:Menu
cls
echo '1 Start'
echo '2 Instructions'
echo '3 Exit'
set /p answer='Type the number of your option and press enter' || SET answer=NO_ANSWER
if %answer%==NO_ANSWER GOTO Menu
if %answer%==1 goto 'Start_1'
if %answer%==2 goto 'Instructions'
if %answer%==3 goto 'Exit'
GOTO Menu
The final GOTO Menu also ensures that the value that was inserted was not just nonsense, for example sdhghdhf or some other invalid value. It will act as the "default" case.
Just copy this kind of structure to every "decision" and it should work fine.

Text based batch game demo, coding mistake

Okay, so, I'm making a crude text-based batch game demo, its a sword-fighting game.... I've never used any sort of coding before, and I taught myself as best I could... I know this is a pretty primitive and easy to learn language, but I don't quite understand what I did wrong... It doesn't process damage to you OR the enemy, and the stat randomizer sometimes give out numbers equal to or below 0... Ive been tweaking, and changing code in ways I don't really understand, trying to fix it, so the code may be a little weird at some parts, feel free the constructively criticize, improve parts that MAY work, and PLEASE find the problems stated... (PS. its also programmed to recognize me as the "creator" and my girlfriend, and calls her by her nickname, but that works fine, so Ill remove it from this code.)
the code:
#echo off
color 02
cls
setlocal enabledelayedexpansion
set file=AdventureTextMusic.mp3
( echo Set Sound = CreateObject("WMPlayer.OCX.7"^)
echo Sound.URL = "%file%"
echo Sound.Controls.play
echo do while Sound.currentmedia.duration = 0
echo wscript.sleep 100
echo loop
echo wscript.sleep (int(Sound.currentmedia.duration^)+1^)*1000) >sound.vbs
start /min sound.vbs
title New Adventurer
echo.
echo Hello Adventurer!
echo.
echo may I ask your name?
echo.
set /p name=
echo.
if %name% equ Michelle goto bunni
if %name% equ Stuart goto kitty
if %name% neq Stuart goto random
:bunni
cls
echo.
echo Bunni? Welcome to my game! I worked hard on it, I don't know if it will be good... We'll see I guess!!
set /a gold=%random% %% 25-1
echo.
echo Here's %gold% gold to get you started! I hope it helps!
echo.
set name=Bunni
echo Good luck %name%!
pause
goto continue
:kitty
cls
echo.
echo Creator? Bug fixing I assume? I hope all is well in the land of Adventure Text! Good luck!
set /a gold=%random% %% 25-1
echo.
echo Here's %gold% gold to get you started! I hope it helps!
pause
goto continue
:random
cls
echo.
echo That name suits you! Welcome %name%! To the land of Adventure Text!
set /a gold=%random% %% 15-1
echo.
echo Here's %gold% gold to get you started! I hope it helps!
echo.
echo Good luck %name%!
pause
goto continue
:continue
cls
echo The controls are simple, when it asks for your choice of attack, pick an option.
echo.
echo Slash does your weapons default damage, minus enemy armor strength, and takes no stamina
echo.
echo Slice does your weapons default damage, ignoring armor strength, and takes 2 stamina
echo.
echo whereas Stab does 1.5 damage, ignoring armor strength, but takes 4 stamina
echo.
pause
cls
echo.
echo Would you like to begin, %name%?
pause
title %name%'s Quest
cls
set /a health=%random% %% 15-1 +2
set /a armor=%random% %% 2-1 +2
set /a damage=%random% %% 4-2 +2
set /a stamina=%random% %% 15-8 +2
echo.
echo Health: %health% Gold: %gold% Armor Strength: %armor% Damage per Hit: %damage% Stamina: %stamina%
pause
cls
echo.
set /a number=%random% %% 2-1
if %number% equ 1 goto Grunt
if %number% equ 2 goto Guard
:Guard
set enemy=Guard
set EHealth=12
set EArmor=1
set EDamage=1
goto battle1
:Grunt
set enemy=Grunt
set EHealth=10
set EArmor=0
set EDamage=2
goto battle1
:battle1
echo An enemy %enemy% has spotted you!
echo Enemy Health: %EHealth% Enemy Armor Strength: %EArmor% Enemy Damage: %EDamage%
pause
cls
echo.
goto turn1
:turn1
echo What would you like to do?
echo 1) Slash
echo 2) Slice
echo 3) Stab
set /p attack=
if %attack% equ 1 goto slash
if %attack% equ 2 goto slice
if %attack% equ 3 goto stab
:turn2
echo Health: !health! Stamina: !stamina!
if !EHealth! leq 0 goto end
echo Enemy Health: !EHealth!
echo Enemy turn!
pause
cls
goto enemy
:enemy
set /a EAttack=%random% %% 3-1
if %EAttack% equ 1 goto Eslash
if %EAttack% equ 2 goto Eslice
if %EAttack% equ 3 goto Estab
if %EAttack% neq 3 goto enemy
:Eslash
set health-=!EDamage!-!armor!
if !health1 leq 0 goto lose
goto turn1
:Eslice
set health-=!EDamage!
if !health! leq 0 goto lose
goto turn1
:Estab
set EDamage*=1.5
set health-=!EDamage!
set EDamage/=1.5
if !health! leq 0 goto lose
goto turn1
:slash
set EHealth-=!damage!-!EArmor!
goto turn2
:slice
if %stamina% lss 2 cls
if %stamina% lss 2 echo.
if %stamina% lss 2 echo You do not have enough stamina to Slice
if %stamina% lss 2 goto turn1
set EHealth-=!damage!
set stamina-=2
goto turn2
:stab
if %stamina% lss 4 cls
if %stamina% lss 4 echo.
if %stamina% lss 4 echo You do not have enough stamina to Stab
if %stamina% lss 4 goto turn1
set damage*=1.5
set EHealth-=!damage!
set damage/=1.5
set stamina-=4-2
goto turn2
:lose
cls
echo.
echo Im sorry %name%... but you lost...
pause
cls
echo This game is in pre-alpha, I will likely be updating it to add the full story.
echo Created by: SteweeBee
pause
taskkill /f /im "wscript.exe"
exit
:end
cls
echo.
echo ---- ---- ---- [----] ------- ----
echo \ \ / \ / / I I I \ I I
echo \ \ / \ / / I I I I\ \I I
echo \ \_/ /\ \_/ / I I I I \ I I
echo \ / \ / I I I I \ I
echo ------ ------ [----] I___I \___I
pause
cls
echo This game is in pre-alpha, I will likely be updating it to add the full story.
echo Created by: SteweeBee
pause
taskkill /f /im "wscript.exe"
exit
set /a health=%random% %% 15-1 +2
The line above is the same as
set /a health=%random% %% 16
and I think you want this:
set /a health=(%random% %% 15-1) +2
The line below uses delayed expansion but you don't use code that requires it (like in loops) - You could just use normal expansion like %health%
!health!
This code will work, unless another character is added when typing and then it will fail. The variable attack should also be initialised before the set /p because set /p will remember what it was the last time through if enter is pressed without input. Input like 1 2 with the space will cause it to fail too (ditto with &).
set /p attack=
if %attack% equ 1 goto slash
if %attack% equ 2 goto slice
if %attack% equ 3 goto stab
It should really have a check for invalid input at the end - just a goto :get_input to loop back for input will do.

Batch File path vairiable %PATH%

I have been creating a chat room for my school, but I have to bring home the file to make changes as they become needed but my problem is the file path has to be changed each time I move the files from one system to another. so I would like to know how to create a %PATH% that will work for me
This is my full code for the main file:
As you may notice I'm new to this
NOTE: Everything here works fine with a set file path but I want it to work easier for when I change computers.
Anything could probably help
#echo off
:Tittle
cls
color 74
title Terms of Service
echo _________________________-Terms-______________________________
echo If you are using this ChatRoom then you agree to the following.
echo *you will not use Horrid Language
echo *you will make your account with either your real name or
echo Student id
echo.
echo This is monitored everyday so if anything is out of line it will be removed.
echo.
echo If you agree to follow these terms then type "yes" otherwise exit.
set /p c=Do you Agree to follow the terms?:
if %c% EQU yes goto Menu
if %c% EQU ADMIN1423 goto Admin
if %c% EQU dad goto Menu
if %c% EQU carrie goto Menu
if %c% EQU dad SET PATH=%PATH%;c:\Users\Dan W Frye\Desktop\(-_-)
:Admin
color 02
cls
Echo
Echo.
Echo 1.) Check User list
Echo.
Echo 2.) Create File Path
Echo.
Echo 3.) Admin Help
Echo.
echo 4.) N/A
echo.
Echo
set /p c=Selection Number:
if %c% EQU 1 goto UserList
if %c% EQU 2 goto CreatePath
if %c% EQU 3 goto AdminHelp
if %c% EQU 4 goto Admin
if %c% EQU back goto Tittle
:UserList
color 0b
cls
title User Listing
cls
start cmd
CALL "%PATH%\Data\Chat Settings\Users\BuAsTeCrHs.bat"
pause
goto Admin
:CreatePath
cls
color 01
echo
echo.
echo The File Path Must look like this(No " "): "Driver (C:)"\Containing folder" thats it the echo rest is automatically "\Data\Chat Settings\Users\....."
echo.
echo
echo.
echo The File Path you want to create.
set /p PATH=File Path:
echo.
echo The Location/Device you are using.
set /p LOC=Location:
echo.
echo %PATH% >>"%PATH%\Data\Chat Settings\File Paths\%LOC%.txt"
echo The file path has been created!
pause
goto Admin
:AdminHelp
pause
goto Tittle
:Menu
color 0b
cls
Echo -[ChatBox]-
Echo
Echo.
Echo 1.) Login
Echo.
Echo 2.) Register
Echo.
Echo 3.) Exit
Echo.
echo 4.) Help
echo.
Echo
Echo.
set /p c=Selection Number:
if %c% EQU 1 goto Login
if %c% EQU 2 goto Register
if %c% EQU 3 exit
if %c% EQU 4 goto help
if %c% EQU 5 goto Terms
:help
cls
echo if you are not able to see the chat log then you must not have
echo the file "Chatroom_reader.bat" open without this you cannot see
echo messages sent by other users.
echo.
echo if you have suggestions or comments then please type "comment"
echo.
echo if you need assistance with any other problem you may have
echo encountered then please type "other" to let the developer know
echo what the problem is. otherwise type "back" to go back to the menu.
set /p c=Option:
if %c% EQU comment goto comments
if %c% EQU other goto other
if %c% EQU back goto menu
:comments
cls
title Comments
echo Enter your Username, and Password to Place a Comment
echo.
set /p UN=Username:
echo.
set /p PW=Password:
echo.
if NOT Exist "%PATH%\Data\Chat Settings\Users\%UN%.txt" Goto Failed
echo %PW% >"%tmp%\chat.tmp"
fc "%tmp%\chat.tmp" "%PATH%\Data\Chat Settings\Users\%UN%.txt" >nul
if errorlevel==1 goto Failed
if errorlevel==0 goto Comment
:Comment
cls
echo.
set /p SUBJECT=Subject:
echo.
set /p COMMENT=Comment:
echo.
echo %SUBJECT% : %COMMENT% >"%PATH%\Data\Chat Settings\Comments\%UN%.txt"
goto User
:other
cls
title Other
echo Enter your Username, and Password to Place a Comment
echo.
set /p UN=Username:
echo.
set /p PW=Password:
echo.
if NOT Exist "C:\Users\Dan W Frye\Desktop\(-_-)\Data\Chat Settings\Users\%UN%.txt" Goto Failed
echo %PW% >"%tmp%\chat.tmp"
fc "%tmp%\chat.tmp" "C:\Users\Dan W Frye\Desktop\(-_-)\Data\Chat Settings\Users\%UN%.txt" >nul
if errorlevel==1 goto Failed
if errorlevel==0 goto OtherA
:OtherA
cls
set /p OTHERC=Other Concern:
echo.
echo %OTHERC% >"%PATH%\Data\Chat Settings\Other\%UN%.txt"
goto User
:Login
cls
echo Enter your Username, and Password to login to the Chat Server
echo.
set /p UN=Username:
echo.
set /p PW=Password:
echo.
if NOT Exist "%PATH%\Data\Chat Settings\Users\%UN%.txt" Goto Failed
echo %PW% >"%tmp%\chat.tmp"
fc "%tmp%\chat.tmp" "%PATH%\Data\Chat Settings\Users\%UN%.txt" >nul
if errorlevel==1 goto Failed
if errorlevel==0 goto User
:User
cls
Echo Welcome %UN% The Current date is %date%
echo
echo.
echo 1.) Chat
echo.
echo 2.) Logout
echo.
echo 3.) Change Password
echo.
echo 4.) Private Chat
echo.
echo 5.) Enter a Private Chat room
echo.
echo
set /p c=Selection Number:
if %c% EQU 1 goto chat
if %c% EQU 2 goto Menu
if %c% EQU 3 goto CHP
if %c% EQU 4 goto PRIVATE
if %c% EQU 5 goto PRIVATENTER
:PRIVATENTER
echo Please enter the name of the Private chat room if you do not know the name you may not enter.
set /p Chat=
if %Chat% EQU scooter goto scooter
if %Chat% EQU Cre-Br goto Cre-Br
:Cre-Br
cls
set name=[%time%]%UN%
cls
color 02
echo Last Message sent by %UN% \/
echo [%time%]%UN%:%text%
set /p text=Say:
echo %name% : %text% >>"%PATH%\Data\Chat Settings\Program_Files\Cre-Br.txt"
goto Cre-Br
:scooter
cls
echo %Chat%
set name=[%time%]%UN%
color 02
echo Last Message sent by %UN% \/
echo [%time%]%UN%:%text%
set /p text=Say:
echo %name% : %text% >>"%PATH%\Data\Chat Settings\Program_Files\scooter.txt"
goto scooter
:PRIVATE
cls
set /p Chat=Chat Name:
echo this is %UN%s Private chat room >>"%PATH%\Data\Chat Settings\Program_Files\%Chat%.txt"
echo.
echo #echo off >>"%PATH%\Data\Chat Settings\Private Chats\%Chat%.bat"
echo color 0b >>"%PATH%H:\(-_-)\Data\Chat Settings\Private Chats\%Chat%.bat"
echo cls >>"%PATH%\Data\Chat Settings\Private Chats\%Chat%.bat"
echo title Message Box >>"%PATH%\Data\Chat Settings\Private Chats\%Chat%.bat"
echo :home >>"%PATH%\Data\Chat Settings\Private Chats\%Chat%.bat"
echo cls >>"%PATH%\Data\Chat Settings\Private Chats\%Chat%.bat"
echo findstr /v "g91dhjt637hsuexv27niw9" "%PATH%\Data\Chat Settings\Program_Files\%Chat%.txt" >>"C:\Users\Dan W Frye\Desktop\Batch\Chat Settings\Private Chats\%Chat%.bat"
echo goto home >>"%PATH%\Data\Chat Settings\Private Chats\%Chat%.bat"
goto User
:CHP
cls
set /p PW=Old Password:
echo.
set /p NP=New Password:
echo %NP% >"%PATH%\Data\Chat Settings\Users\%UN%.txt
goto User
:Register
cls
color 07
echo Register (Note the username is your screen name Please use your real name or School ID EX, CaBu56789)
echo.
set /p NU=Username:
echo.
set /p NP=Password:
echo.
echo %NP% >"%PATH%\Data\Chat Settings\Users\%NU%.txt"
echo.
cls
goto login
:Failed
color 0c
cls
echo You have entered am invalid Username and or Password
echo Please try again or Register for free
pause
goto menu
:chat
set name=[%time%]%UN%
cls
color 02
echo Everything said here is on recored please mind your
echo language!
echo Last Message sent by %UN% \/
echo [%time%]%UN%:%text%
set /p text=Say:
echo %name% : %text% >>"%PATH%\Data\Chat Settings\Program_Files\ChatRoom.txt"
goto chat
%PATH% is reserved environment variable, documented here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/path.mspx?mfr=true
For diagnostics purposes you could echo that variable to analyze if that has such value you intended to have:
echo %path%
As mentioned by #Jermu Virtanen the %PATH% variable is a windows system set path...you should not use/change it unless you really know what you are doing.
So instead of using %PATH% use something like %PROGPATH%.
Also as mentioned by #foxdrive, if the user enters "dad" it will go to "menu" before setting the path variable. And again if you instead chose 'Admin' then to 'List users' it will again be calling the path without first setting it.
You could automate some of the login or path settings by grabbing the computer's domain name %userdomain% and current user %username%.
Ie;
SET "progpath=c:\Users\%username%\Desktop\(-_-)"
In your code the path was being set after it had already branched to the menu. This may work for you:
if %c% EQU carrie goto Menu
if %c% EQU dad SET PATH=%PATH%;c:\Users\Dan W Frye\Desktop\(-_-)& goto menu
To put the batch file on the path for every user, use this:
set path=%path%;%PUBLIC%
and copy the batch file to C:\Users\Public and run it from there.
Unless it needs extra permissions it should run from there for every user.

"Counter" in Batch

I'm trying to make a Batch file that will increment a variable by 1 each time it loops, and then check if the variable is equal to 5, and if it isn't, it loops again. I know there's probably a while loop for this, but I didn't know how to do that, and I'm just enjoying learning Batch for fun right now
Here's the code, it doesn't work the way it should, it just displays a 0: and then does nothing else. So how would I go about fixing it? I have a feeling I'm setting and incrementing the variable wrong, and maybe it's confused about the 2 if statements? (Does it have an else if....?) Anyways, thanks for the help
#echo off
set /p i=0:
goto A
:A
set /p i=i+1:
if i != 5 goto C
if i == 5 goto B
:C
echo Test :D
:B
pause>nul
Note: I don't know a lot of Batch and I'm not a pro, but I like to learn and I'm just doing this for future reference, and because I enjoy it. So, this code probably isn't good, but I want to know how I can accomplish this.
This is a way to simulate the while loop you are trying to accomplish. Only one goto is needed:
#echo off
set /a x=0
:while
if %x% lss 5 (
echo %x%
pause>nul
set /a x+=1
goto :while
)
echo Test :D
You can do that with a simple FOR command :
for /l %%x in (0,1,100) do (
echo %%x
)
You can replace 100 by the number you want
To set a numerical value to a variable, you may use the /a switch:
The /A switch specifies that the string to the right of the equal sign
is a numerical expression that is evaluated.
(Type SET /? for all the help).
Second, check your goto flow - this never loops back to A.
Third, check the syntax of the if expression (!= doesn't exist in batch).
This should work:
#echo off
set var1=0
:loop
set /a var1=%var1%+1
echo %var1%
if %var1% EQU 5 (
goto :end
) else (
goto :loop
)
:end
pause
#echo off
set a=0
:Count
set /a a=a+1
echo %a%
goto Count
try this:
#if (#CodeSection == #Batch) #then
#echo off
:a
cls
color c
echo --------------
echo start:
echo --------------
set /p start=
cls
echo --------------
echo start: %start%
echo --------------
echo --------------
echo stop:
echo --------------
set /p stop=
cls
echo --------------
echo start: %start%
echo --------------
echo --------------
echo stop: %stop%
echo --------------
echo.
echo.
echo Start in:
timeout /t 2 /nobreak >nul
echo. 5
timeout /t 1 /nobreak >nul
echo. 4
timeout /t 1 /nobreak >nul
echo. 3
timeout /t 1 /nobreak >nul
echo. 2
timeout /t 1 /nobreak >nul
echo. 1
timeout /t 1 /nobreak >nul
cls
echo --------------
echo start: %start%
echo --------------
echo --------------
echo stop: %stop%
echo --------------
echo.
echo.
echo.
echo ============================================
set SendKeys=CScript //nologo //E:JScript "%~F0"
%SendKeys% ">----"
%SendKeys% "{enter}"
:while
echo %start%
%SendKeys% "%start%"
%SendKeys% "{enter}"
set /a start=start+1
timeout /t 1 /nobreak >nul
if %start% leq %stop% goto :while
goto :end
:end
echo ============================================
%SendKeys% ">----"
%SendKeys% "{enter}"
:c
echo count again? Y/N
set /p return=
if %return% == Y goto :a
if %return% == N goto :b
goto :c
:b
#end
var WshShell = WScript.CreateObject("WScript.Shell");
WshShell.SendKeys(WScript.Arguments(0));

Resources