[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-02-17
13
Medium Priority
?
352 Views
Last Modified: 2012-05-06
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.
0
Comment
Question by:Acip
  • 5
  • 3
  • 3
  • +1
13 Comments
 
LVL 47

Expert Comment

by:Donald Stewart
ID: 23665943
something like this?



@echo off
:beginning
cls
set /p user=what is your name?
if not %user%==%username% goto beginning
echo thank you
0
 
LVL 6

Expert Comment

by:Justin_W_Chandler
ID: 23666035
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
 

Author Comment

by:Acip
ID: 23674223
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 47

Expert Comment

by:Donald Stewart
ID: 23674265
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
 

Author Comment

by:Acip
ID: 23676887
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
 
LVL 16

Accepted Solution

by:
t0t0 earned 2000 total points
ID: 23702695
@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
 
LVL 16

Expert Comment

by:t0t0
ID: 23702709
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
 

Author Closing Comment

by:Acip
ID: 31548090
Thanks for this solution...works just as I had hoped.
Great job!
0
 

Author Comment

by:Acip
ID: 23703358
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
 
LVL 47

Expert Comment

by:Donald Stewart
ID: 23703362
this is for the AT syntax

http://support.microsoft.com/kb/313565
0
 
LVL 16

Expert Comment

by:t0t0
ID: 23704293
Acip

thank you for accepting my solution

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

0
 
LVL 6

Expert Comment

by:Justin_W_Chandler
ID: 23726434
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
 

Author Comment

by:Acip
ID: 23727135
Hi Justin -

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

Acip
0

Featured Post

Restore individual SQL databases with ease

Veeam Explorer for Microsoft SQL Server delivers an easy-to-use, wizard-driven interface for restoring your databases from a backup. No expert SQL background required. Web interface provides a complete view of all available SQL databases to simplify the recovery of lost database

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

YESTERDAY YESTERDAY.BAT is inspired by a previous article I wrote entitled: TOMORROW.BAT (http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/MS_DOS/A_4196-Advanced-Batch-File-Programming-TOMORROW-BAT.html). The crux of this batch f…
This article was inspired by a question here at Experts Exchange (http://www.experts-exchange.com/Software/Photos_Graphics/Images_and_Photos/Q_28629170.html). The requirements stated in that question are (1) reduce the file size of a large number of…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question