kb2002 - An example of DOS batch file (SDK)

This article contains downloadable template

Get user input from batch file


Sure, you've done it, but can you do it without having to hit a Ctrl-Z, without ANSI, without a debug script, and without a separate "set" file?



Get user input and mask passwords with HTML


HTML forms can mask passwords as you enter them, so use forms! Here I show you how to have your batch file create a username/password form, then use Windows Scripting to read the contents of that form and transfer the results back into a batch file. As shown, it uses the environment, so you may need to modify things if your target computers don't have room.



Get user input and mask password with HTA


HTML Applications (HTA files) can do everything ordinary HTML can, but there is no need to separate the HTML from the scripting in order to save the results to the hard drive. Like the above HTML method, this creates a batch file named "userin.bat" in the "temp" directory which can be called by your batch file to retrieve the data.



Mask passwords with QBASIC


QBASIC allows you to grab user input without echoing it to the screen. This makes it easy to throw an asterisk up for every character that gets entered. Again, this code stores the password in the environment for your batch file to use. FYI, Win9x boxes don't come with QBASIC installed by default. See here for how to get QBASIC and here for how to install it automatically.



Get user input from an NT batch file


All the old tricks fail. Luckily, QBASIC can be used and is standard equipment in NT. Windows Scripting works better if you have it.



Accept arguments in any order


Simon Richardson shows how to use structured batch programming (as best as batch can do it) to collect arguments. Then I show how to break that structure.


Accept arguments in any order


Fred Fisher said he could improve on the above method to collect arguments. I think you'll agree he did! He does it with a few more IFs and a lot less GOTOs. He demonstrates three separate argument types. One is a switch, another takes one argument, and the last takes two separate arguments. You can easily simplify (or extend) the code for any number of arguments each taking any number of parameters.



How to get around the "Do you really want to do this?" prompt.


Have your batch file send the desired answer..



How to simulate typing to any program.


Send your program keystrokes whether it is a DOS or Windows program. This isn't "User Input", but is more along the lines of simulating a user who isn't there. Great for automating programs that weren't designed to be automated.



0 comments: