Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
I am trying to make a batch file with a oassword and a timer but this is as far as I have gotten:
_____________________________________________@echo off
echo You have 30 seconds to find the password.
set choice=
set /p choice=Type the letter to print text.
if not '%choice%'=='' set choice=%choice:~0,6%
if '%choice%'=='yruynn' goto 1
ECHO %choice% is wrong! HAHA!
ECHO.
goto final
:1
echo You have gotten the password correct!
pause
:final
echo HAHA!
pause
_____________________________________________Can u help?
I hope you can help!

Timing your batch is almost impossible as the Set /P command is a synchronous query not allowing a timer to tick while the input is expected.
A workaround may be planned involving a child task, but that is a ugly and over complex solution.
Better to find another coding schema.

Could I get rid of the /P and replace it or something? What would happen?
Cheese, the more you eat it, the less you care about how mouldy it is!

I have changed the /P with/S and It has worked. Sort of... No matter where I put:
ping 1.1.1.1 -n 1 -w 30000 > nul
It always freezes the whole file. Can I set it so it counts subliminally and does not stop the file from running?
Here is the improved version.
_____________________________________________@echo off
echo You have 30 seconds to find the password.
set choice=
set /s choice=Type the letter to print text.
if not '%choice%'=='' set choice=%choice:~0,6%
ping 1.1.1.1 -n 1 -w 30000 > nul
if '%choice%'=='yruynn' goto 1
ECHO %choice% is wrong! HAHA!
ECHO.
goto final
:1
echo You have gotten the password correct!
pause
:final
echo HAHA!
pause
_____________________________________________Got any pointers?
Cheese, the more you eat it, the less you care about how mouldy it is!

Stated that entering (and then checking) a password by using a batch script is absolutely unsafe, your issue has not an easy solution with batch language (even with NT batch extensions).
Via the Choice.exe command that you can google and download, as it is not standard in XP, you can request a *single* char response and time it if nothing is entered, but not a whole string.
As I said, that is not a task to be performed via batch.

"I have changed the /P with/S and It has worked. Sort of... No matter where I put:
ping 1.1.1.1 -n 1 -w 30000 > nul
It always freezes the whole file."A quick look at set /? shows no /s option.
Better heed #1. If IVO can't do it, it proabably ain't gonna get done.
=====================================
If at first you don't succeed, you're about average.M2

I suppose to be a good scripter untill I saw your batch; what means Set /S? I never saw the /S switch associated with the Set command. So please explain.

Well, I have always had a thing with the letter s and scince without the /p at all it is exactly the same as the line before so I thought that I should add a letter and /s came to mind. It runs the timer now but not the choice. Mabye I could try /p and /s?
Cheese, the more you eat it, the less you care about how mouldy it is!

I'm always ready to learn.
Newton and Maxwell did an extraordinary work on mechanic and electromagnetic forces, but Einstein went outer their limits, and Quantum Physics did what Einstein refused.
So I'm ready to learn from hatlad if he can prove his code.

"Mabye I could try /p and /s?"
You sure could. Best way to learn.
I don't know if I would characterize frezong up as working 'sort of'; more like working 'not at all'.
=====================================
If at first you don't succeed, you're about average.M2

Hi hatlad,
under some limits coding and the IT are not experimental sciences; as a genaral rule you find what you are searching in a rationale process; there are amazing exceptions, but those are not the rule.
You must know what are you coding (i mean syntax and semantics of your commands).
Now I stop here, beacause I'm becoming too serious and I'm a kid in my heart as M2 well knows.

Well, now that I put set/p and set/s on separate lines, it ignores /s whenever I put /p and without /p it never gives the option of having a choice. Is there a way to bypass /p but still have the effect of a choice?
Here is the newest version:
_____________________________________________
@echo off
title Warning: Password Required!
echo You have 30 seconds to find the password.
set choice=
set /p choice=Type the letter to print text.
set /s choice=ping 1.2.3.4 -n 1 -w 5000 > nul
if not '%choice%'=='' set choice=%choice:~0,6%
if '%choice%'=='yruynn' goto 1
ECHO.
goto final
:1
echo You have gotten the password correct!
pause
exit
:final
echo HAHA!
ping 1.2.3.4 -n 1 -w 1000 > nul
_____________________________________________Cheese, the more you eat it, the less you care about how mouldy it is!

::== pw.bat
@echo off
setLocal EnableDelayedExpansionecho enter 2 char pw, 5 sec limit for each char
choice /c:dz /n /s /t:z,5
if errorlevel 2 goto :eof
set c1=d
echo first char is !c1!choice /c:oz /n /s /t:z,5
if errorlevel 2 goto :eof
set c2=o
echo second char is !c2!echo pw is !c1!!c2!
goto :eof
CHOICE [/C[:]choices] [/N] [/S] [/T[:]c,nn] [text]
/C[:]choices Specifies allowable keys. Default is YN
/N Do not display choices and ? at end of prompt string.
/S Treat choice keys as case sensitive.
/T[:]c,nn Default choice to c after nn seconds
text Prompt string to displayERRORLEVEL is set to offset of key user presses in choices.
::==
=====================================
If at first you don't succeed, you're about average.M2

It says choice is not a know comand. Is there something I need to download?
Cheese, the more you eat it, the less you care about how mouldy it is!

http://golden-triangle.com/CHOICE.COM
=====================================
If at first you don't succeed, you're about average.M2

restricted e-mail on campus. Wont work
Cheese, the more you eat it, the less you care about how mouldy it is!

Has what to do with email?
=====================================
If at first you don't succeed, you're about average.M2

sorry, I meant internet
Cheese, the more you eat it, the less you care about how mouldy it is!

Find a PC running win98. Or a w98 CD.
=====================================
If at first you don't succeed, you're about average.M2

Oh well I will try to use my newly discovered set /sto toy with stuff. I have know idea what I will be doing but the is a slight chance that a time portal will open up from this PC and suck me into a future where everyone has been timing a choice with batch for milenia!
Cheese, the more you eat it, the less you care about how mouldy it is!

What is the campus block, my site or COM files?
=====================================
If at first you don't succeed, you're about average.M2

Never mind M2...
as he said, he passed through a Stargate that will push him to an amazing world where IT is unknown!

We can only hope he'll dial into a black hole, which will confine all further frivolity to the event horizon
"Is there something I need to download?"
Yes indeed... a clue
Censorship is the tool of those who have the need to hide actualities from themselves and others. Their fear is only their inability to face what is real.

![]() |
![]() |
![]() |

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.
| Ads by Google |