Computing.Net > Forums > Programming > timing a choice

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

timing a choice

Reply to Message Icon

Name: hatlad
Date: June 20, 2007 at 10:30:22 Pacific
OS: win xp home
CPU/Ram: intel pentium 512 ram
Product: custom
Comment:

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!



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: June 20, 2007 at 14:16:26 Pacific
Reply:

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.


0

Response Number 2
Name: hatlad
Date: June 21, 2007 at 09:30:23 Pacific
Reply:

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!


0

Response Number 3
Name: hatlad
Date: June 21, 2007 at 09:40:37 Pacific
Reply:

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!


0

Response Number 4
Name: IVO
Date: June 21, 2007 at 09:44:49 Pacific
Reply:

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.


0

Response Number 5
Name: Mechanix2Go
Date: June 21, 2007 at 09:52:39 Pacific
Reply:

"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



0

Related Posts

See More



Response Number 6
Name: IVO
Date: June 21, 2007 at 09:52:40 Pacific
Reply:

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.


0

Response Number 7
Name: hatlad
Date: June 21, 2007 at 09:58:18 Pacific
Reply:

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!


0

Response Number 8
Name: IVO
Date: June 21, 2007 at 09:59:30 Pacific
Reply:

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.


0

Response Number 9
Name: Mechanix2Go
Date: June 21, 2007 at 10:08:14 Pacific
Reply:

"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



0

Response Number 10
Name: IVO
Date: June 21, 2007 at 10:09:22 Pacific
Reply:

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.


0

Response Number 11
Name: hatlad
Date: June 21, 2007 at 10:10:01 Pacific
Reply:

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!


0

Response Number 12
Name: Mechanix2Go
Date: June 21, 2007 at 10:37:20 Pacific
Reply:

::== pw.bat
@echo off
setLocal EnableDelayedExpansion

echo 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 display

ERRORLEVEL is set to offset of key user presses in choices.

::==



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 13
Name: hatlad
Date: June 21, 2007 at 10:43:44 Pacific
Reply:

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!


0

Response Number 14
Name: Mechanix2Go
Date: June 21, 2007 at 10:51:55 Pacific
Reply:

http://golden-triangle.com/CHOICE.COM



=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 15
Name: hatlad
Date: June 21, 2007 at 10:55:10 Pacific
Reply:

restricted e-mail on campus. Wont work

Cheese, the more you eat it, the less you care about how mouldy it is!


0

Response Number 16
Name: Mechanix2Go
Date: June 21, 2007 at 10:57:09 Pacific
Reply:

Has what to do with email?


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 17
Name: hatlad
Date: June 21, 2007 at 10:59:21 Pacific
Reply:

sorry, I meant internet

Cheese, the more you eat it, the less you care about how mouldy it is!


0

Response Number 18
Name: Mechanix2Go
Date: June 21, 2007 at 11:01:14 Pacific
Reply:

Find a PC running win98. Or a w98 CD.


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 19
Name: hatlad
Date: June 21, 2007 at 11:15:13 Pacific
Reply:

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!


0

Response Number 20
Name: Mechanix2Go
Date: June 21, 2007 at 12:43:52 Pacific
Reply:

What is the campus block, my site or COM files?


=====================================
If at first you don't succeed, you're about average.

M2



0

Response Number 21
Name: IVO
Date: June 21, 2007 at 13:26:31 Pacific
Reply:

Never mind M2...

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


0

Response Number 22
Name: jboy
Date: June 22, 2007 at 15:48:34 Pacific
Reply:

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.


0

Sponsored Link
Ads by Google
Reply to Message Icon






Post Locked

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


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: timing a choice

How to set a default choice in bat? www.computing.net/answers/programming/how-to-set-a-default-choice-in-bat/17081.html

Education Q? A fork in the road www.computing.net/answers/programming/education-q-a-fork-in-the-road/4591.html

Logon VBScript to Launch EXE www.computing.net/answers/programming/logon-vbscript-to-launch-exe/19295.html