1.

Solve : batch file not working?

Answer»

hi i GOT a code earlyer and i edited it a bit well alot and its not working if anoyone can spot the problen plz reply

Code: [Select]@echo off
set try=3
cd "%userprofile%"
echo. >> log.txt
echo Logged In>> Log.txt
echo %userprofile% >> Log.txt
echo %Date% %time% >> Log.txt
goto start
:fail
cd "%userprofile%"
echo. >> log.txt
echo password incorrect>> log.txt
echo %userprofile% >> log.txt
echo %date% %time% >> log.txt
echo password attempts left %try% >> log.txt
:start
echo plase type password
set /p "pass=>"
if %pass%==password (goto stop) else (goto incorrect)
:stop
cd "%userprofile%"
echo __________>> log.txt
echo password correct
pause
exit
:incorrect
if %try%==0 goto shutdown
set /a "try= %try% - 1"
you have %try% trys left before shutdown
pause
goto fail
:shutdown
echo you have used up all your trys system is shutting down
shutdown -s -f -t 10
cd "%userprofile%"
echo. >> log.txt
echo all atempts used>> log.txt
echo shutdown at %date% %time%>> log.txt
echo reason: password incorrect 3 times>> log.txt
echo __________> log.txt
pause
exitItems in RED are my REPLACEMENTS.

@echo off
set try=3
cd "%userprofile%"
echo. >> log.txt
echo Logged In>> Log.txt
echo %userprofile% >> Log.txt
echo %Date% %time% >> Log.txt
goto start
:fail
cd "%userprofile%"
echo. >> log.txt
echo password incorrect>> log.txt
echo %userprofile% >> log.txt
echo %date% %time% >> log.txt
echo password attempts left %try% >> log.txt
:start
echo plase type password
set /p "pass=>"
if not "%pass%"=="password goto incorrect
:stop
cd "%userprofile%"
echo __________>> log.txt
echo password correct
pause
exit
:incorrect
if %try%==0 goto shutdown
set /a try-=1
echo you have %try% tries left before shutdown
pause
goto fail
:shutdown
echo you have used up all your trys system is shutting down
shutdown -s -f -t 10
cd "%userprofile%"
echo. >> log.txt
echo all atempts used>> log.txt
echo shutdown at %date% %time%>> log.txt
echo reason: password incorrect 3 times>> log.txt
echo __________> log.txt
pause (this is UNNEEDED)
exit

That took about 2 minutes...PRETTY simple stuff...I didn't look that hard, but it should work now.it still not working as soon as i press enter to enter the password it goes away Quote from: Helpmeh on April 19, 2009, 09:57:26 AM

Items in red are my replacements.

@echo off
set try=3
cd "%userprofile%"
echo. >> log.txt
echo Logged In>> Log.txt
echo %userprofile% >> Log.txt
echo %Date% %time% >> Log.txt
goto start
:fail
cd "%userprofile%"
echo. >> log.txt
echo password incorrect>> log.txt
echo %userprofile% >> log.txt
echo %date% %time% >> log.txt
echo password attempts left %try% >> log.txt
:start
echo plase type password
set /p pass=^>
if not "%pass%"=="password goto incorrect
:stop
cd "%userprofile%"
echo __________>> log.txt
echo password correct
pause
exit
:incorrect
if %try%==0 goto shutdown
set /a try-=1
echo you have %try% tries left before shutdown
pause
goto fail
:shutdown
echo you have used up all your trys system is shutting down
shutdown -s -f -t 10
cd "%userprofile%"
echo. >> log.txt
echo all atempts used>> log.txt
echo shutdown at %date% %time%>> log.txt
echo reason: password incorrect 3 times>> log.txt
echo __________> log.txt
pause (this is unneeded)
exit

That took about 2 minutes...pretty simple stuff...I didn't look that hard, but it should work now.
That should do it.Quote
if not "%pass%"=="password goto incorrect

Spot the error

Also:

Quote
echo plase type password

This is how you spell "please".

Quote
echo you have used up all your trys system is shutting down

The plural of try is tries.



Quote from: Dias de verano on April 19, 2009, 01:15:33 PM
Spot the error


Lol...I can't believe I missed that...this is so wrong, if you try to password-protect your pc with batch and put the batch file in startup folder, it's the most silly thing i've ever heard.
cmd batch run in a seperate process, in it's own box. To terminate it, i just need to press Ctrl-C or click on the X mark to close the box or just do nothing.

plz use the built-in user account:
Start-->Control panel-->user accountQuote
Quote
echo plase type password
This is how you spell "please".
Quote
echo you have used up all your trys system is shutting down
The plural of try is tries.

If BATCH is lexicographically sensitive,
- I better give it up altogether

yea but my dad my mum and my brother dont know that and any way the peice of code isent finished

also i found somin else
changes in red
Code: [Select] @echo off
set try=3
cd "%userprofile%"
echo. >> log.txt
echo Logged In>> Log.txt
echo %userprofile% >> Log.txt
echo %Date% %time% >> Log.txt
goto start
:fail
cd "%userprofile%"
echo. >> log.txt
echo password incorrect>> log.txt
echo %userprofile% >> log.txt
echo %date% %time% >> log.txt
echo password attempts left %try% >> log.txt
:start
echo plase type password
[color=red]set /p "pass=>" [/color]
if not "%pass%"=="password goto incorrect
:stop
cd "%userprofile%"
echo __________>> log.txt
echo password correct
pause
exit
:incorrect
if %try%==0 goto shutdown
set /a try-=1
echo you have %try% tries left before shutdown
pause
goto fail
:shutdown
echo you have used up all your trys system is shutting down
shutdown -s -f -t 10
cd "%userprofile%"
echo. >> log.txt
echo all atempts used>> log.txt
echo shutdown at %date% %time%>> log.txt
echo reason: password incorrect 3 times>> log.txt
echo __________> log.txt
exit
thanks for your helpQuote
if not "%pass%"=="password goto incorrect

there is a quote mark missing at the end of "password

This will cause a syntax error.
Quote from: steven32collins on April 20, 2009, 09:17:54 AM
also i found somin else
changes in red
Code: [Select] @echo off
set try=3
cd "%userprofile%"
echo. >> log.txt
echo Logged In>> Log.txt
echo %userprofile% >> Log.txt
echo %Date% %time% >> Log.txt
goto start
:fail
cd "%userprofile%"
echo. >> log.txt
echo password incorrect>> log.txt
echo %userprofile% >> log.txt
echo %date% %time% >> log.txt
echo password attempts left %try% >> log.txt
:start
echo plase type password
[color=red]set /p "pass=>" [/color]
if not "%pass%"=="password goto incorrect
:stop
cd "%userprofile%"
echo __________>> log.txt
echo password correct
pause
exit
:incorrect
if %try%==0 goto shutdown
set /a try-=1
echo you have %try% tries left before shutdown
pause
goto fail
:shutdown
echo you have used up all your trys system is shutting down
shutdown -s -f -t 10
cd "%userprofile%"
echo. >> log.txt
echo all atempts used>> log.txt
echo shutdown at %date% %time%>> log.txt
echo reason: password incorrect 3 times>> log.txt
echo __________> log.txt
exit
The quotes shouldn't be required. Please not that you must escape the greater than character (as I did in a previous post).Quote from: Helpmeh on April 20, 2009, 03:14:06 PM
The quotes shouldn't be required. Please not that you must escape the greater than character (as I did in a previous post).

Either no quotes at all or two sets. One set no good.

Quote from: Dias de verano on April 20, 2009, 03:44:21 PM
Either no quotes at all or two sets. One set no good.


I was talking about set /p "pass=>" is his code. This is what needs to be done: set /p pass=^>


Discussion

No Comment Found