I need a batch file that accepts user input and compares it to a fixed string.

I need a batch file that accepts user input and compares it to a fixed string.
I'm trying to avoid the "strike any key to continue" scenario that one might get with a pause command...i.e. batch should wait for user input, check the input against a stored value (say, username) and only close once the input string compares correctly with the stored value.
AcipAsked:
Who is Participating?
 
t0t0Connect With a Mentor Commented:
@echo off
set string=ok
:start
set input=
set /p input=Enter [%string%] to continue:
if "%input%"=="" goto :start
if not %input%==%string% goto :start
0
 
DonNetwork AdministratorCommented:
something like this?



@echo off
:beginning
cls
set /p user=what is your name?
if not %user%==%username% goto beginning
echo thank you
0
 
Justin_W_ChandlerCommented:
It might be a good idea to add:

break off

If you give more details to exactly what you're trying to accomplish I'm sure we could make something very useful for you. Batch scripting is extremely powerful for buliding console-based applications.
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
AcipAuthor Commented:
What I'm looking for is an announcement that will persist on the user's monitor that will persist until a specific string is entered by the user.

I was originally using netsend to push the announcement to appropriate targets, but some users have disabled messenger service, and some users type right past the message and consequently don't see the announcement. Still others aren't in the same domain, and consequently don't get the netsend message.

Nice thing about netsend is that it left a record in the event logs that the message was received.
My workaround is to run a batch file locally on each target box as an "at" job.
I don't know how to make a local batch file that will meet these criteria:

The suggestion first offered here can be dismissed with the <ENTER> key, so won't be persistent.
I want to require the user to enter a specific string, so that it will be a conscious effort on their part to dismiss the popup message. In the example below, I'm trying to use "OK" as the validation string...

@echo off
cls
echo <Alert message here>

:loopit
set /p user=Enter "OK" to acknowledge receipt of this message:
if %user%==OK goto thank
if not %user%==OK echo Please type "OK"
goto loopit

:thank
echo thank you
pause
0
 
DonNetwork AdministratorCommented:
No matter how you do it in a batch file, you can dismiss it by closing it "X"
 
I suggest doing it with VBS
0
 
AcipAuthor Commented:
I'm not concerned about users clicking the X, or using the ALT+F4 keystroke.
Both of these are deliberate.
I'm trying to prevent the batch from closing when a user types nothing but <ENTER>
How to make the DOS box persistent when a user hits the <ENTER> key?
0
 
t0t0Commented:
A variation to the above uses the system environment variable USERNAME.

@echo off
:start
set input=
set /p input=Enter [%username%] to continue:
if "%input%"=="" goto :start
if not %input%==%username% goto :start
0
 
AcipAuthor Commented:
Thanks for this solution...works just as I had hoped.
Great job!
0
 
AcipAuthor Commented:
Thanks t0t0...I had used the env variable %username% earlier, but didn't know how to make it not accept an  key.

All I need now is to push this to target machines and run an at job to schedule it...
Have you any pointers on the AT syntax? (Other than what's available by typing at/?)
 at 13:00 /every M,T,W,Th,F

0
 
DonNetwork AdministratorCommented:
this is for the AT syntax

http://support.microsoft.com/kb/313565
0
 
t0t0Commented:
Acip

thank you for accepting my solution

sorry, i can't help you with AT commands at the moment

0
 
Justin_W_ChandlerCommented:
What are you trying to accomplish with the AT command? I'm an expert at Windows console scripting. Perhaps I can help.

Justin Chandler
0
 
AcipAuthor Commented:
Hi Justin -

I've resolved the issue... /cmd c works wonders.
No need for follow-up.

Acip
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.