Solved How do I write a batch to run a .exe program

September 3, 2012 at 09:16:17
Specs: Windows 7
I'm just getting into messing around with computer programming and such. Most of us are all familiar with the batch file that creates a private folder that you can lock and require a password. I am trying to change some of the scripting so that If you do not type in the correct password on the first attempt it shuts down your computer.
The original batch is:

cls
@ECHO OFF
title Folder Private
if EXIST "HTG Locker" goto UNLOCK
if NOT EXIST Private goto MDLOCKER
:CONFIRM
echo Are you sure you want to lock the folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Private "HTG Locker"
attrib +h +s "HTG Locker"
echo Folder locked
goto End
:UNLOCK
echo Enter password to unlock folder
set/p "pass=>"
if NOT %pass%==password goto FAIL
attrib -h -s "HTG Locker"
ren "HTG Locker" Private
echo Folder Unlocked successfully
goto End
:FAIL
echo Invalid password
goto end
:MDLOCKER
md Private
echo Private created successfully
goto End
:End


I created a basic shutdown program, shutdown -s -t 1 -c "Virus Upload Begun"
The shutdown program works great by itself but I cannot get the program to start with a failed password attempt.
Here is what I have:

cls
@ECHO OFF
title Folder Private
if EXIST "HTG Locker" goto UNLOCK
if NOT EXIST Private goto MDLOCKER
:CONFIRM
echo Are you sure you want to lock the folder(Y/N)
set/p "cho=>"
if %cho%==Y goto LOCK
if %cho%==y goto LOCK
if %cho%==n goto END
if %cho%==N goto END
echo Invalid choice.
goto CONFIRM
:LOCK
ren Private "HTG Locker"
attrib +h +s "HTG Locker"
echo Folder locked
goto End
:UNLOCK
echo Enter password to unlock folder
set/p "pass=>"
if NOT %pass%==password goto FAIL
attrib -h -s "HTG Locker"
ren "HTG Locker" Private
echo Folder Unlocked successfully
goto End
:FAIL
start "C:\Windows\System32\shutdown.exe"
goto End
:MDLOCKER
md Private
echo Private created successfully
goto End
:End

Any and all help is appreciated!


See More: How do I write a batch to run a .exe program

Report •

#1
September 3, 2012 at 14:21:56
✔ Best Answer
I would recommend not using the "start" command, but just jump out to a "kill" batch or execute the shutdown right from your batch::
if NOT %pass%==password shutdown -t 0 -f -s

or, if you want to modularize it:
if NOT %pass%==password kill.bat

and kill.bat has same contentas above: @shutdown -t 0 -f -s

:note: tested xp, NOT tested on Seven.


Report •

#2
September 4, 2012 at 18:37:38
thanks! worked like a charm

Report •
Related Solutions


Ask Question