Link to home
Start Free TrialLog in
Avatar of Acip
Acip

asked on

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.
Avatar of Don
Don
Flag of United States of America image

something like this?



@echo off
:beginning
cls
set /p user=what is your name?
if not %user%==%username% goto beginning
echo thank you
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.
Avatar of Acip
Acip

ASKER

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
No matter how you do it in a batch file, you can dismiss it by closing it "X"
 
I suggest doing it with VBS
Avatar of Acip

ASKER

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?
ASKER CERTIFIED SOLUTION
Avatar of t0t0
t0t0
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Avatar of Acip

ASKER

Thanks for this solution...works just as I had hoped.
Great job!
Avatar of Acip

ASKER

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

this is for the AT syntax

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

thank you for accepting my solution

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

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

Justin Chandler
Avatar of Acip

ASKER

Hi Justin -

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

Acip