1.

Solve : Creating a password protect batch file with a batch file?

Answer»

Hey everyone, I'm fairly new at programming at everything, but I'm trying to learn, so bear with me.

I created a batch file, for fun, to shut down a computer in 60 seconds, but creates a text file and a second password protected batch file to ABORT the shutdown.

This is the code I've used.

Code: [Select]ECHO OFF
MODE CON: COLS=70 LINES=6
TITLE Shutdown - By Matt
START C:\Windows\System32\shutdown.exe -s -t 60 -c "Shutting Down"
ECHO Warning! Your computer will shutdown in 60 seconds! > shutdown.txt
ECHO. >> shutdown.txt
ECHO To abort, run the "abort" batch file on your desktop. >> shutdown.txt
ECHO echo off > abort.bat
ECHO MODE CON: COLS=20 LINES=5 >> abort.bat
ECHO title abort >> abort.bat
ECHO color 9B >> abort.bat
ECHO :Start >> abort.bat
ECHO cls >> abort.bat
ECHO set /p password="Password: " >> abort.bat
ECHO if "%password%"=="qwerty" goto :correct >> abort.bat
ECHO goto :Start >> abort.bat
ECHO :correct >> abort.bat
ECHO cls >> abort.bat
ECHO echo Password correct! >> abort.bat
ECHO C:\Windows\System32\shutdown.exe -a >> abort.bat
ECHO pause \nul >> abort.bat
ECHO exit >> abort.bat
START C:\Users\%USERNAME%\Desktop\shutdown.txt
COLOR 9B
ECHO.
ECHO --------------------------------------------------------------------
ECHO Run abort.bat and enter the password
ECHO Now press any key to delete the two files created by this batch file.
ECHO --------------------------------------------------------------------
ECHO.
PAUSE
DEL C:\Users\%USERNAME%\Desktop\shutdown.txt
DEL C:\Users\%USERNAME%\Desktop\abort.bat
EXIT
It shuts down properly, creates and opens the text file properly, but I run into problems with the second batch file.

This is the code it puts into the second batch file:

Code: [Select]echo off
MODE CON: COLS=20 LINES=5
title abort
color 9B
:Start
cls
set /p password="Password: "
if ""=="qwerty" goto :correct
goto :Start
:correct
cls
echo Password correct!
C:\Windows\System32\shutdown.exe -a
pause \nul
exit
The password portion of the file won't rune because it doesn't add Code: [Select]%password% into it.

Does anybody know of a way to make it add that into the second batch file, or a second way of writing a password command that will work?

Thanks,
- MattI wrote a complete explanation of why you had this result and how to avoid it BUT I had second thoughts. I deleted it. This sounds like a PRANK.


What do you mean a prank?

Please help me find a way to fix this? I'm just learning and created a file to test my knowledge.Solved Thanks to "mat123".

Thanks so much.

The solution was to put %%password%% instead of just %password%. Quote from: MattPwns on July 02, 2010, 02:13:15 PM

What do you mean a prank?

Please help me find a way to fix this? I'm just learning and created a file to test my knowledge.

A prank is where you put a script on somebody elses computer for a joke to see their alarm and surprise. So that you pwn them. (Your name tells me a lot)

Way to help a prankster mat123.
but, it would show them how to stop it...

I created this to test my knowledge as i said before, and now i am trying to find a wait for it to start automatically after 10 minutes or something.

Ill probably put a new batch file into the startup folder, and run wait command of some SORT then open this one.

Again bro, it's just for fun and personal USE.


Discussion

No Comment Found