[an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] 24x7 Script Archive


How to send a keystroke to a DOS application

The SendKeys statement does not work with the DOS (console) application. This is by design of the Windows/95/98/NT/2000. However, there are limited workarounds available for this issue.

Win 95/98 solution: Copy the desired keystroke to the clipboard as a text. SendKeys "{ALT} EP" To the DOS window. This works like you click on the Control Menu of the DOS window then select the Edit/Paste command.

Example:

Dim proc, number

Run "c:\bin\myprog.exe", "c:\bin", proc
// copy to the clipboard my name followed by the TAB key followed by my password followed by the ENTER key.
ClipboardSet "myname\tmypassword\r"
// simulate DOS Edit/Paste command
SendKeys "{ALT} EP"

Common solution (Win 95/98/NT/2000): Redirect DOS based application input to a file. Use Windows Notepad to create a text file containing the keystroke that you want send just like you type it in your DOS application. Perhaps, this file name is INPUT.TXT. Run your program using the following command:

Example:

Dim proc, number

Run "c:\bin\myprog.exe < c:\bin\input.txt", "c:\bin", proc

Note: same techniques can be used in the command line parameter of jobs of the Program type.