I wrote two .bat files that each have a problem that I can't figure out and it's driving me crazy.
This one is a simple virus deleter I wrote for people in my school. The computers have a virus that create an Autorun.inf file and put a .exe called srv32.exe in the RECYCLER folder on flash drives. So I made this to delete them. I have it set up so that they can enter which drive they want to delete by using set. Here's the code:
@echo off
title Nash's Anti Virus
color b0
echo WELCOME TO NASH'S ANTI VIRUS.
echo.
echo -This is a VERY basic program designed to delete the KNOWN viruses on the WITS
echo computers.
echo.
echo -I do not guarantee to find / delete all viruses, just the ones known to ME.
echo.
echo -If the program tells you that you had a virus and it was deleted and you get it again, then the computer you used has the virus and you have to use a different computer.
echo.
echo Have Fun!
echo.
pause
echo.
set /p know= If you know what letter your drive is, enter the letter Y. If you do not know how to find what letter your drive is enter N -
if %know%==N (
type W:\instruct.txt
echo.
pause
echo.
echo.
set /p drive= Enter the letter of the drive that you want to be cleaned from the virus -
echo.
cd /d %drive%:\
cd
dir /A:H
del /a:shr autorun.inf
rd /s /q RECYCLER
rd /s /q .Trashes
del /a:h ._.trashes
echo.
pause
cls
if exist autorun.inf echo YOU HAD THE VIRUS AND IT WAS DELETED
if not exist autorun.inf echo YOU DID NOT HAVE THE VIRUS
echo.
echo Thank you for using Nash's Anti Virus
echo.
)
if %know%==Y (
echo.
echo.
echo.
set /p drive= Enter the letter of the drive that you want to be cleaned from the virus.
echo.
cd %drive%:\
cd
dir /A:H
del /a:shr autorun.inf
rd /s /q RECYCLER
rd /s /q .Trashes
del /a:h ._.trashes
echo.
pause
cls
if exist autorun.inf echo YOU HAD THE VIRUS AND IT WAS DELETED
if not exist autorun.inf echo YOU DID NOT HAVE THE VIRUS
echo.
echo Thank you for using Nash's Anti Virus
echo.
)
pause
But for some reason it's doesn't work. Any ideas?
The other one is just for fun, but I hit an error at the last step. Code is:
@ECHO off
title How are you today?
color 1A
echo Welcome to Nash's mood central! Follow the following instructions as they say.
echo All answers MUST be in CAPS.
pause
set /p name= What is your name? -
echo Hello %name%, how are you today? -
set /p mood=(Enter GOOD or BAD)
if %mood%==GOOD (
echo.
@echo Great! Have an awesome day!
echo.
echo THE PROGRAM WILL EXIT WHEN YOU PRESS ANY KEY.
echo.
pause
)
if %mood%==BAD (
echo.
@echo Aw That stinks. Feel Better!
echo.
set /p choice= For more words of encouragment, type MORE. To exit, type GET ME OUTTA HERE!
)
if %choice%==GET ME OUTTA HERE! exit
if %choice%==MORE (
echo The sun will come out tommorrow...
echo.
set /p choice= For more words of encouragment, type MORE. To exit, type GET ME OUTTA HERE!
)
if %choice%==GET ME OUTTA HERE! exit
if %choice%==MORE (
echo.
echo Don't be mad, get Glad!
echo.
set /p choice= For more words of encouragment, type MORE. To exit, type GET ME OUTTA HERE!
)
if %choice%==GET ME OUTTA HERE! exit
if %choice%==MORE (
echo NO WONDER YOUR DAY STINKS, YOU'RE SPENDING ALL YOUR TIME AT THIS COMPUTER...
echo.
set /p choice= For more words of encouragment, type MORE. To exit, type GET ME OUTTA HERE!
)
if %choice%==GET ME OUTTA HERE! exit
if %choice%==MORE (
echo Go find a hobby! May I suggest Magic?
echo.
set /p choice= For more words of encouragment, type MORE. To exit, type GET ME OUTTA HERE!
)
if %choice%==GET ME OUTTA HERE! exit
if %choice%==MORE (
echo How about a coffee? -
set /p c=Enter YES or NO
)
if %c%=YES (
echo No can do. I'm only a computer!
)
if %c%=NO (
echo Good, I can't get you one anyway...
)
echo.
set /p choice= For more words of encouragment, type MORE. To exit, type GET ME OUTTA HERE!
pause
When they type YES or NO for the last step it closes the .bat.
Any help is appreciated.
Can someone tell me what's wrong with these?
Moderator: DosItHelp
Re: Can someone tell me what's wrong with these?
Hi magicbyuriel,
the main problems in your code are the comparisions.
If someone type in "Not not" then your line will expand to
That is legal but absolutly not that what you want.
Always enclose variables, that should solve most of your problems
jeb
the main problems in your code are the comparisions.
Code: Select all
if %know%==N (
...
If someone type in "Not not" then your line will expand to
Code: Select all
if Not not==N (
That is legal but absolutly not that what you want.
Always enclose variables, that should solve most of your problems
Code: Select all
if "%know%"=="N" (
jeb