We may need to know to which directory a file is to be copied, for example. Or which drive needs to be formatted. How you can manage to retrieve user input depends on the OS version used, and whether you want to allow "third party" tools or use "native code" only.
This command will display an optional promptString where the user can type in a string and press Enter. The typed string will then be stored in the specified environment variable variable. Duke Communications International, Inc. My own DialogBoxes executables, written in C can be used to display messages and ask for input in Windows XP and later versions.
Walter Zackery posted two interesting solutions to obtain user input in NT , on the alt. It will actually change drive C:'s volume label and then restore it again to its old value. Besides that the batch file limits the string to 2 words 1 space only. I adapted the original postings so that the batch files no longer need to use temporary files. You can view the original postings at my Solutions found at alt.
Another great solution by Eric Phelps uses a temporary HTA file to obscure a password while it is being typed. BAT and N. Guess what happened if a user typed a completely different answer. Many PC users and batch file authors including myself , find this approach "less intuitive", to say the least. One would expect that pressing the enter key is enough, and once you find out it isn't, the previous line of input cannot be removed anymore.
The previous example is only a bare minimum. COM is loaded. With a few minor adjustments replace. BAT with. Hint: For debugging it is very helpful to remove echo off temporarily Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow.
Learn more. Asked 6 years, 4 months ago. Active 6 years, 4 months ago. Viewed times. Soumya ranjan Rout. Soumya ranjan Rout Soumya ranjan Rout 3 4 4 bronze badges. Add a comment. EXE does its best to try and interpret doublequotes, it can easily be fooled. Even if it doesn't allow cross-scripting so far, it may still cause the batch file to terminate with an error. Try again, with the entire line in doublequotes, i. The text 'test2' is not recognized as an internal or external command,operable program or batch file indicates successful code insertion — or at least, it might have been successfull Try other "randomly" inserted doublequotes, use more arguments, combine them with ampersands, and see if you can successfully predict the results Note: Try test1 "test2 ; if an opening doublequote is not terminated by a closing doublequote "test2 in this example , CMD.
EXE will just assume a doublequote at the end of the command line. It may be clear from the demonstration above that it is hard, if possible at all, to completely prevent code insertion in batch files.
0コメント