To Prepare Batch Script - batch-file

Please help to prepare batch script on DOS.
This script should run in following manner :
Telent the IP and use the existing passwd (explicitly given in the script).
After the telnet, it shows MENU options
MB station
RC
ODU
AP
SU
Exit
type 1 // a "MB station" MENU options will open i.e.
1 - Show
2 - Unit Control
type 2 // UC MENU options will open i.e
1 - Change Password
2 - Reset
type 1 //change passwd MENU options will open i.e.
1 - Change PC Password
2 - Change LU Password
3 - Change Admin Password
type 3 // to change ADMIN passwd
MB station - Change Admin Password
Enter New Password : XYZ enter
Re-enter Password : XYZ enter
New password accepted
3 times escape // to escape from telnet
1.MB station
2. RC
3. ODU
4. AP
5. SU
6. Exit
type 6 // to exit
Exit? [Y/N] y
Connection to host lost.
then move to step with different IP. The IP values will be given by the user one-time while executing the script at the prompt e.g. ./pass-change IPs.txt

start with this :
#ECHO OFF
:BEGIN
CLS
ECHO.
ECHO Oleg Grishko + Flora = Love
ECHO.
ECHO.
ECHO 1=Remove All Hard Drive Partitions
ECHO 2=FDISK Hard Drive
ECHO 3=Format Hard Drive
ECHO 4=Dell Utilities
ECHO 5=Re-image
ECHO 6=Exit To DOS
ECHO.
ECHO To bring this menu back type GO.BAT at the dos prompt.
ECHO.
CHOICE /N /C:123456
ECHO.
If ERRORLEVEL ==6 GOTO SIX
If ERRORLEVEL ==5 GOTO FIVE
If ERRORLEVEL ==4 GOTO FOUR
IF ERRORLEVEL ==3 GOTO THREE
IF ERRORLEVEL ==2 GOTO TWO
IF ERRORLEVEL ==1 GOTO ONE
GOTO END
:SIX
EXIT
GOTO QUIT
:FIVE
call re-image.bat
GOTO END
:FOUR
call dell.bat
GOTO END
:THREE
cd dos
call format.bat
GOTO END
:TWO
cd dos
call fdisk.bat
GOTO END
:ONE
cd dos
call blast.bat
GOTO END
:END
cd\
REM ECHO Completed. Bringing up DOS menu again...
REM pause
REM f:go.bat
:QUIT
f:

Related

Incorrect syntax when asking for user input

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.

Is it possible to create an interactive notepad within batch script that saves users input

I'm in the process of creating a mini-game using batch and one of the useful tool ideas was to have an interactive notepad so that users could store information throughout the game and refer back to it later. So far I have created the option to goto a notepad within an In-game pause menu but wasn't sure if it was possible to save results without outputting to new file on the desktop
:PauseMenu
cls
echo.
echo %Alias%
echo.
echo Notepad
echo Stats
echo Untitled2
echo Untitled3
echo Untitled4
echo Untitled5
echo Untitled6
set/p PauseMenu="N, S"
IF ["%PauseMenu%"]==["N"] goto Notepad
IF ["%PauseMenu%"]==["S"] goto Stats
IF ["%PauseMenu%"]==["N"] goto
IF ["%PauseMenu%"]==["N"] goto
IF ["%PauseMenu%"]==["N"] goto
IF ["%PauseMenu%"]==["N"] goto
IF ["%PauseMenu%"]==["N"] goto
Any help would be appreciated, thanks.
PS is it possible to go back to the previous page from a menu?
Simplicity itself.
First, some renaming may be in order. notepad is a supplied utility and pausemenu is being used both as a variable and as a label. This is not invalid, but can be a little confusing.
Further, if you are choosing between a set of keys, I'd suggest you investigate choice. choice has a number of advantages, like it only accepts one character, no enter is required and it's not necessary to analyse the entry.
So: revising your code:
:p_pausemenu
pause
:PauseMenu
cls
echo.
echo %Alias%
echo.
echo N Notepad
echo S Stats
echo 1 Untitled2
echo Z Untitled3
echo Q Untitled4
echo J Untitled5
echo X Untitled6
:: Note that the processing of ERRORLEVEL must be in reverse order
choice /c ns1zqjx
if errorlevel 7 goto labelx
if errorlevel 6 goto labelj
if errorlevel 5 goto labelq
if errorlevel 4 goto labelz
if errorlevel 3 goto label1
if errorlevel 2 goto stats
if errorlevel 1 goto unotepad
:unotepad
start "Notes for %alias%" notepad "c:\gamedirectory\%alias%.txt"
goto pausemenu
:stats
:: List your stats here
echo Stats for %alias%
goto p_pausemenu
Here, a menu with a number of unimplemented options is presented and the choice command (see choice /? from the prompt for more options) waits for a choice to be made.
errorlevel is set according to the choice made - but since if errorlevel n means if errorlevel is n OR GREATER THAN n you need to process errorlevel in reverse order.
Then each selection is processed. n will start a notepad instance and load the alias.txt file from the game directory, then present the menu again as it returns to pausemenu. s will show the stats (idk what you need for that) and then return to p_pausemenu which will pause and then proceed to show the menu when the user signals to do so.

Reading a Text File and Reacting (Batch)

I looked for quite a while and couldn't find a good solution to my problem. I want a batch program to "look" in a .txt file for the command "" and if that word is in it, then to execute a different command. If the command existed, I would want to do something like set %textfile%=text.txt and if that worked I would then do if %textfile%==update goto update which would be an easy way to start an automatic update if this was in a loop. So basically, is there a command that sets a text file in %text%? This is the code that I am trying to add this into:
#echo off
color 0f
:start
echo Welcome to Master control pannel
ping 127.1 -n 4 >nul
cls
:options
cls
echo What would you like to do first? (Type the number of the operation you want to start)
echo.
ping 127.1 -n 2 >nul
echo 1. Run a command off of all computers
::(I want to run a command by sending a message to a text file but want recieving computor to be able to read it and execute it, how could I read the command and then do what it say, for example, if the command says "echo Hello" I would want recieving computor to say "Hello" )
echo 2. Stops the current command
echo 3. List all computers
echo 4. Open remote shutdown program
echo 5. Delete a computor (in progress)
echo 6. (Unfinished)
echo 7. (Unfinished)
echo 8. (Unfinished)
echo 9. (Unfinished)
echo 10. Exit
set /p choose=(1-9):
if %choose%==1 goto o1
if %choose%==2 goto o2
if %choose%==3 goto o3
if %choose%==4 goto o4
if %choose%==5 goto o5
if %choose%==6 goto close
if %choose%==7 goto close
if %choose%==8 goto close
if %choose%==9 goto close
if %choose%==10 goto o10
goto options
:close
cls
goto start
:o1
echo Stopping current command
del command.txt
echo. 2>command.txt
echo Command stopped!
pause
cls
goto start
I would greatly appreciate some help or comments to what I could do or add to this. Thanks!
Not an answer but several hints.
a variable can hold only single lines not a whole file.
if you want to get the first line of a file into a var use `Set /P "var="
set %textfile%=text.txt would store test.txt literally into a var whose name is the content of the var textfile.
you are mixing goto o1 and :01 with the label
`

My batch file skips specific loops

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

print choice command output batch file

I have this type of command but I want to print the result
command below:
ECHO Access to this system is restricted to authorized personnel for authorized business purpose only!!
CHOICE /M "Do you want to continue"
If Errorlevel 2 GoTo N
:Y
ECHO.
ECHO You choose: YES
set /p id=Enter Name/ID:
ECHO Hello %id%
timeout /t 5
GoTo ErrorFunc
:N
Echo.
Echo You choose: NO and you are required to exit from cmd !
Echo.
ECHO EXITING IN 5 SECOND
timeout /t 5
exit
test.bat > C:\test.log
If I type Y and print the result, it will stuck the result below:
Access to this system is restricted to authorized personnel for
authorized business purpose only!! Do you want to continue [Y,N]?
Any idea for a solution?
To add selections to your question, simply use
CHOICE /C:yn /M "Do you want to continue?"
if %ERRORLEVEL% EQU 1 GOTO Y
if %ERRORLEVEL% EQU 2 GOTO N
ERRORLEVEL 1 indicates the first selection which is /C:yn, ERRORLEVEL 2 indicates the second selection which is /C:yn.

Resources