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. The following batch file checks if ANSI. SYS is loaded.
If so, it will tell the user to press the Enter key only. If not, it will tell the user to press F6 first, followed by the Enter key. However, to check if ANSI. There are many batch utilities on the web that help ask for user input.
I will list some of them here:. It creates a temporary batch file to set an environment variable to the typed input. An example batch file, with the resulting PM window:. My LoginDialog. It is possible to write batch files using PowerShell without requiring a temporary PowerShell script. This is where PowerShell's -Command switch comes in handy.
All commands coming after REM or :: are considered as comments by the console. This command allows you to go directly to a specific location in a batch file. The executed batch file is stopped and the console displays the message Press any key to continue…. This command allows you to call a batch file from another batch file.
Example: The following example call SecondScript. This command allows you to read and delete variables in the command prompt. This command allows you to change the title of the command prompt window. This command allows you to start some programs or some commands. Example: The following example will start two programs called Notepad and Calculator.
This command allows you to closes the session, restarts the computer, or shuts it down. Example: The following example will shut down your computer in 60 seconds. This command allows you to search for one or more files by using character input. This command allows you to display data page by page on the screen.
Example: The following example will display the content of myFile. This command allows you to display the contents of text files. This command allows you to test the connection with another device. Example: The following example will ping a website example. Your email address will not be published. Windows I have also added a goto because if you typed something that isn't a yes or a no then it would have automatically gone to yes.
Failing the below code you could add this but the code at the bottom should work. Another much simpler way to do this in two lines, without using the IF statement is this:. This tool allows users to select one item from a list of choices and returns the index of the selected choice. In this example, 1 will be returned when y is pressed, and 2 will be returned when n is pressed.
EDIT: You are kind of on track, but you just were using the wrong commands. Another way you could implement my fix is this:. It is full of sooo much information. This also removes any id10t user errors, meaning anything the user could do to try to break it or use it wrong. That way, you catch if they don't enter either Yes or No and catch if they enter any variation of Yes or No. It's hard to get more simple than that, there's only one command-flag not four, it doesn't depend on Command Extensions and there's little question of version-compatibility.
In terms of validation, well, the user has to put in the right parameter. If they don't, it's wrong. Simple as that. Echo it back to confirm with a pause and the user can control-break out of it. Could more time be spent arguing the pros and cons of different approaches? Is that wise? Probably not.
0コメント