|
|
|
Need Help With Batch Script
|
Original Message
|
Name: Stuby085
Date: January 6, 2004 at 14:47:37 Pacific
Subject: Need Help With Batch Script OS: WinME CPU/Ram: Intel Pentium III 866/512
|
Comment: Hello. I'm Running a WinME and have wrote a batch file to change some helpful things. It works up until it accepts the user input for the choice variable. However, once it reaches this part no matter what you press (of the allowed buttons) it always returns a errorlevel of one. Could someone please tell me what I have done wrong or why it only accepts one as the errorlevel? Thanks. @echo off REM This is the main screen where the choices are displayed. echo Hello. What would you like to play? echo. echo 1.) Dad's Ultima Online echo 2.) Josh's Ultima Online echo 3.) The OFFLINE Server echo 4.) Sorry, I'm stupid and would like to exit...(HeHe) echo. echo. REM This is where the choice itself is made and interpeted accordingly. choice /c:1234 /n /t:4,10 Please press the corresponding number to what you wish to choose: REM The errorlevel is (or by all means should be) set as the number pressed. if errorlevel = 1 goto :dad if errorlevel = 2 goto :josh if errorlevel = 3 goto :server if errorlevel = 4 goto :time_to_quit :dad REM This checks to see if the file is there, and if not it continues though is id does is redirects the script. if exist C:\Program Files\Ultima Online 2D\login.cfg goto :login REM This changes the directory to the root directory and then enters into the C:\Program Files\Ultima Online 2D folder. cd\ cd Program Files cd Ultima~1 REM In DOS this is short for C:\Program Files\Ultima Online 2D. REM This makes a file named login.cfg in the folder C:\Program Files\Ultima Online 2D. It then makes the file contain everything mentioned after the "echo" and before the ">>". echo ;Loginservers for Ultima Online >> login.cfg echo ;Do not edit this file or patching will fail! Always save a backup. >> login.cfg echo LoginServer=login.owo.com,7775 >> login.cfg echo LoginServer=login.owo.com,7775 >> login.cfg echo LoginServer=login.owo.com,7776 >> login.cfg echo LoginServer=login.owo.com,7776 >> login.cfg REM This states to the user that the program will exit and then counts down from three with a one second pause between each number. echo Exiting in: echo 3 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 2 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 1 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo Bye Bye TYPE NUL | CHOICE.COM /N /CY /TY,3 >NUL cls exit :login REM If C:\Program Files\Ultima Online 2D\login.cfg exists this deletes it and then redirects the script. cd\ cd Program Files cd Ultima~1 del login.cfg goto :dad :josh REM This checks to see if the file is there, and if not it continues though is id does is redirects the script. if exist C:\Program Files\Ultima Online 2D\login.cfg goto :login2 REM This changes the directory to the root directory and then enters into the C:\Program Files\Ultima Online 2D folder. cd\ cd Program Files cd Ultima~1 REM In DOS this is short for C:\Program Files\Ultima Online 2D. REM This makes a file named login.cfg in the folder C:\Program Files\Ultima Online 2D. It then makes the file contain everything mentioned after the "echo" and before the ">>". echo ;Login information for Oblivion >> login.cfg echo LoginServer=shard.aleknights.com,2593 >> login.cfg echo you chose number 2 echo Exiting in: echo 3 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 2 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 1 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo Bye Bye TYPE NUL | CHOICE.COM /N /CY /TY,3 >NUL cls exit :login2 REM If C:\Program Files\Ultima Online 2D\login.cfg exists this deletes it and then redirects the script. cd\ cd Program Files cd Ultima~1 del login.cfg goto :josh :server REM This checks to see if the file is there, and if not it continues though is id does is redirects the script. if exist C:\Program Files\Ultima Online 2D\login.cfg goto :login3 REM This changes the directory to the root directory and then enters into the C:\Program Files\Ultima Online 2D folder. cd\ cd Program Files cd Ultima~1 REM In DOS this is short for C:\Program Files\Ultima Online 2D. REM This makes a file named login.cfg in the folder C:\Program Files\Ultima Online 2D. It then makes the file contain everything mentioned after the "echo" and before the ">>". echo ; login.cfg file for the Admin server >> login.cfg echo LoginServer=127.0.0.1,2593 >> login.cfg echo Exiting in: echo 3 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 2 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 1 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo Bye Bye TYPE NUL | CHOICE.COM /N /CY /TY,3 >NUL cls exit :login3 REM If C:\Program Files\Ultima Online 2D\login.cfg exists this deletes it and then redirects the script. cd\ cd Program Files cd Ultima~1 del login.cfg goto :server :time_to_quit REM This leaves a messages and then does a count-down to close. echo. echo. echo Fine! If you want to be a quitter then that's just fine! echo. TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo Bye Bye TYPE NUL | CHOICE.COM /N /CY /TY,3 >NUL cls exit
Report Offensive Message For Removal
|
|
Response Number 1
|
Name: FishMonger
Date: January 6, 2004 at 19:18:20 Pacific
Subject: Need Help With Batch Script |
Reply: (edit)The proper syntax is to use 2 equals signs. if errorlevel == 1 goto :dad if errorlevel == 2 goto :josh if errorlevel == 3 goto :server if errorlevel == 4 goto :time_to_quit
Report Offensive Follow Up For Removal
|
|
Response Number 2
|
Name: Code One
Date: January 6, 2004 at 20:35:56 Pacific
Subject: Need Help With Batch Script
|
Reply: (edit)i disagree, check out my script... @echo off :start cls :: :menu cls echo. echo Menu echo. echo. echo 1) Delete Files echo 2) Edit Delete.bat echo 3) Exit echo. choice:/c123 /n Make a menu selection: if errorlevel 3 goto end if errorlevel 2 goto edit if errorlevel 1 goto del :: :del cls CALL delete pause goto start :: :edit cls cd\ C:\WINDOWS\NOTEPAD.EXE C:\MYDOCU~1\BAT Post\delete.bat cls goto start :: :end
run that and see if it works.
Report Offensive Follow Up For Removal
|
|
Response Number 3
|
Name: Code One
Date: January 6, 2004 at 23:37:04 Pacific
Subject: Need Help With Batch Script
|
Reply: (edit)in fact try this: @echo off :start cls :: echo Hello. What would you like to play? echo. echo 1.) Dad's Ultima Online echo 2.) Josh's Ultima Online echo 3.) The OFFLINE Server echo 4.) Exit echo. echo. choice:/c 1234 /n /t:4,10 Select a menu selection: if errorlevel 4 goto end1 if errorlevel 3 goto login if errorlevel 2 goto josh if errorlevel 1 goto dad :: :dad cls if exist C:\Program Files\Ultima Online 2D\login.cfg goto :login cd\ cd Program Files cd Ultima~1 REM In DOS this is short for C:\Program Files\Ultima Online 2D. echo ;Loginservers for Ultima Online >> login.cfg echo ;Do not edit this file or patching will fail! Always save a backup. >> login.cfg echo LoginServer=login.owo.com,7775 >> login.cfg echo LoginServer=login.owo.com,7775 >> login.cfg echo LoginServer=login.owo.com,7776 >> login.cfg echo LoginServer=login.owo.com,7776 >> login.cfg echo Exiting in: echo 3 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 2 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 1 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo Bye Bye TYPE NUL | CHOICE.COM /N /CY /TY,3 >NUL cls goto exit :: :login REM If C:\Program Files\Ultima Online 2D\login.cfg exists this deletes it and then redirects the script. cd\ cd Program Files cd Ultima~1 del login.cfg goto dad :: :josh cls if exist C:\Program Files\Ultima Online 2D\login.cfg goto :login2 cd\ cd Program Files cd Ultima~1 REM In DOS this is short for C:\Program Files\Ultima Online 2D. echo ;Login information for Oblivion >> login.cfg echo LoginServer=shard.aleknights.com,2593 >> login.cfg echo you chose number 2 echo Exiting in: echo 3 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 2 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 1 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo Bye Bye TYPE NUL | CHOICE.COM /N /CY /TY,3 >NUL cls goto exit :: :login2 REM If C:\Program Files\Ultima Online 2D\login.cfg exists this deletes it and then redirects the script. cd\ cd Program Files cd Ultima~1 del login.cfg goto josh :server cd\ cd Program Files cd Ultima~1 REM In DOS this is short for C:\Program Files\Ultima Online 2D. echo ; login.cfg file for the Admin server >> login.cfg echo LoginServer=127.0.0.1,2593 >> login.cfg echo Exiting in: echo 3 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 2 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 1 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo Bye Bye TYPE NUL | CHOICE.COM /N /CY /TY,3 >NUL cls goto exit :login3 REM If C:\Program Files\Ultima Online 2D\login.cfg exists this deletes it and then redirects the script. cd\ cd Program Files cd Ultima~1 del login.cfg goto :server :: :end1 REM This leaves a messages and then does a count-down to close. echo. echo. echo Fine! If you want to be a quitter then that's just fine! echo. TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo Bye Bye TYPE NUL | CHOICE.COM /N /CY /TY,3 >NUL cls :: :exit ======================================= Man, I seriously tried to correct this bat file, but you may have more mistakes in it, I seen alot, and fixed what I saw. Maybe this will get you on the right foot.
hope so code one
Report Offensive Follow Up For Removal
|
|
Response Number 4
|
Name: Code One
Date: January 6, 2004 at 23:53:05 Pacific
Subject: Need Help With Batch Script
|
Reply: (edit)OK, ok, call me a fanatic but i went back and fixed all the errors in the code i could the rest is up to you, what you need to do is shorting the path names, there are too many paramenters, they must be in dos form to work (e.g., C:\PROGRA~1\etc.) there are too many parameters in all top three choices, (e.g., dad, josh, offline), fix that and you'll be in buisness. Also, the count down to exit is cool, but can get annoying so I would think twice about keeping that in. Anyway, I fixed the code and as far as the menu goes, it works, just change the path names to DOS format and your in like flin. heres your new code: @echo off :start goto menu :: :menu cls echo Hello. What would you like to play? echo. echo 1.) Dad's Ultima Online echo 2.) Josh's Ultima Online echo 3.) The OFFLINE Server echo 4.) Exit echo. echo. choice:/c1234 /n Select a menu selection: if errorlevel 4 goto end1 if errorlevel 3 goto login if errorlevel 2 goto josh if errorlevel 1 goto dad :: :dad cls if exist C:\Program Files\Ultima Online 2D\login.cfg goto :login cd\ cd Program Files cd Ultima~1 REM In DOS this is short for C:\Program Files\Ultima Online 2D. echo ;Loginservers for Ultima Online >> login.cfg echo ;Do not edit this file or patching will fail! Always save a backup. >> login.cfg echo LoginServer=login.owo.com,7775 >> login.cfg echo LoginServer=login.owo.com,7775 >> login.cfg echo LoginServer=login.owo.com,7776 >> login.cfg echo LoginServer=login.owo.com,7776 >> login.cfg echo Exiting in: echo 3 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 2 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 1 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo Bye Bye TYPE NUL | CHOICE.COM /N /CY /TY,3 >NUL pause goto exit :: :login REM If C:\Program Files\Ultima Online 2D\login.cfg exists this deletes it and then redirects the script. cd\ cd Program Files cd Ultima~1 del login.cfg pause goto dad :: :josh cls if exist C:\Program Files\Ultima Online 2D\login.cfg goto :login2 cd\ cd Program Files cd Ultima~1 REM In DOS this is short for C:\Program Files\Ultima Online 2D. echo ;Login information for Oblivion >> login.cfg echo LoginServer=shard.aleknights.com,2593 >> login.cfg echo you chose number 2 echo Exiting in: echo 3 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 2 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 1 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo Bye Bye TYPE NUL | CHOICE.COM /N /CY /TY,3 >NUL pause goto exit :: :login2 REM If C:\Program Files\Ultima Online 2D\login.cfg exists this deletes it and then redirects the script. cd\ cd Program Files cd Ultima~1 del login.cfg pause goto josh :server cd\ cd Program Files cd Ultima~1 REM In DOS this is short for C:\Program Files\Ultima Online 2D. echo ; login.cfg file for the Admin server >> login.cfg echo LoginServer=127.0.0.1,2593 >> login.cfg echo Exiting in: echo 3 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 2 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo 1 TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo Bye Bye TYPE NUL | CHOICE.COM /N /CY /TY,3 >NUL pause goto exit :login3 REM If C:\Program Files\Ultima Online 2D\login.cfg exists this deletes it and then redirects the script. cd\ cd Program Files cd Ultima~1 del login.cfg pause goto server :: :end1 REM This leaves a messages and then does a count-down to close. echo. echo. echo Fine! If you want to be a quitter then that's just fine! echo. TYPE NUL | CHOICE.COM /N /CY /TY,1 >NUL echo Bye Bye TYPE NUL | CHOICE.COM /N /CY /TY,3 >NUL pause cls :: :exit ======================================= also, you outta take a look at those other labes (e.g., login2, login3, etc) You may want to redirect the gotos to actually goto those as well, doesnt look like there even gone to, so tweak that and the parameters, and your set. good luck ;) code one
Report Offensive Follow Up For Removal
|
Use following form to reply to current message:
|
|

|