Solved

Create a batch file that prompts user to press any key to exit

Posted on 2009-07-06
7
9,735 Views
Last Modified: 2012-05-07
I created a batch file however, I am want a command that will prompt the user to echo "Press any key to exit" and that once the key is entered it will exit.
0
Comment
Question by:gm5522
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 2
7 Comments
 
LVL 43

Expert Comment

by:Steve Knight
ID: 24787199
@echo off
rem the rest of your batch
pause
cls
exit

Is that what you mean?
Steve
0
 
LVL 43

Accepted Solution

by:
Steve Knight earned 500 total points
ID: 24787206
If you want it to specifically say that:

@echo off
echo Press any key to exit
pause > nul
cls
exit
0
 
LVL 70

Expert Comment

by:Qlemo
ID: 24787896
Normally, you would just add the pause command at the end of your batch. Nothing else is needed.
0
Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

 
LVL 43

Expert Comment

by:Steve Knight
ID: 24788253
Agreed.... the pause is the important bit :-)
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24789974
All you need to add to your code are the following three lines:

   ECHO Press any key to exit
   PAUSE >NUL
   EXIT /B



You don't need these lines:

   @echo off
   cls

And be careful with the EXIT command because without the '/B' switch, EXIT will close down your DOS session too.
 
0
 
LVL 43

Expert Comment

by:Steve Knight
ID: 24791803
toto you are just being pedantic now :-) I imagine the guy just wanted to know of pause... and in general at least someone running a batch file from a cmd window wouldn't need a press any key to exit...  the cls and exit is from older versions? of windows that would not close the window if something showed on the screen.... habit but not normally needed now as you say.
0
 
LVL 16

Expert Comment

by:t0t0
ID: 24834676
I don't suppose the asker knows how to split points between contributors....

So, he went with the CLS then?....
0

Featured Post

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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