Welcome to HBH! If you have tried to register and didn't get a verification email, please using the following link to resend the verification email.

simple batch file with a fair few uses


ghost's Avatar
0 0

this is a batch file for running on NT it speaks for its self any problems read the remarks in the file

Rem echos off
echo off
rem clear
cls
rem building menus
echo +------------------------------+
echo ¦ sam hacking project     ¦
echo ¦------------------------------¦
echo ¦ Tch0rts batch file n00b ¦
echo +------------------------------+
echo.
echo.
echo.
echo +------------------------------+
echo ¦Options¦
echo ¦------------------------------¦
echo ¦1. Scandisk ¦
echo ¦2. defrag ¦
echo ¦3. Drive contents ¦
echo ¦4. copy sams to floppy ¦
echo ¦5. format C drive :
echo ¦6. shutdown system ¦
echo ¦7. exit     ¦
echo.
echo.

CHOICE /n /c:1234567 Please selct the option you require
echo off
rem define error levels

if errorlevel=7 goto end
if errorlevel=6 goto shut
if errorlevel=5 goto format
if errorlevel=4 goto copy
if errorlevel=3 goto list
if errorlevel=2 goto defrag
if errorlevel=1 goto scan

:scan
rem launch scandisk
scan
goto menu

:defrag
rem launch defrag
defrag
goto menu

:list
rem list files
dir c:\*.* /s/p
pause
goto menu

:copy
rem copy sams
copy C:\WINDOWS\system32\config a:\
goto menu

:format
rem format c
format c:\
goto menu

:shut
rem shutdown system
shutdown -s 10

:end
rem end of file```

ghost's Avatar
0 0

The shutdown line only logs off my computer. Add -s and it should shut down.


dami3n's Avatar
Member
0 0

Guess u was right for running on NT only

on my xp comp it comes up with

'CHOICE' is not recognized as an internal or external command, operable program or batch file.

Ah well :P


ghost's Avatar
0 0

mastergamer wrote: The shutdown line only logs off my computer. Add -s and it should shut down. changed thanks for the heads up :happy:


Uber0n's Avatar
Member
0 0

Well the CHOICE command was integrated in all Windows versions until someone at M$ decided to remove it in XP…:xx: Don't know why, it was the easiest way to create a simple batch menu…. But it's easy enough to write a C++ program which works in the same way :D.

Btw, I've written a C++ program which works almost in the same way. 1. It takes your input (Like a number, a letter, a word etc) 2. It creates a temp batch file which loads %VARI% with the value you entered 3. It executes the batch file, loading the variable (now you can view it in DOS by typing SET) 4. It deletes the batch file.

So, for using it just do something like this in the batch file:

REM Get variable ECHO Enter your choice ECHO. CALL inputter.exe ECHO You entered %VARI%

You can also do something like

CALL inputter.exe IF .%VARI%==.1 GOTO CONTINUE IF .%VARI%==.2 GOTO END

or

CALL inputter.exe IF NOT .%VARI%==.poo ECHO You didn't enter the word poo!

If you want source (if you don't want to write your own, of course :p) feel free to PM me.

Peace B)