Automate Application - How to answer a prompt in a batch file

Solution 1:

You can use VBScript to do that. Use AppActivate to bring the window onto the screen:

Set objShell = CreateObject("WScript.Shell")
objShell.AppActivate "notepad"

Then use SendKeys to send the required keys:

'Wait a second before we do anything
WScript.sleep 1000

intCount=0

'Send the keys to notepad application
Do While intCount <= 10
  wshShell.SendKeys "Line No: " 
  wshShell.SendKeys intCount 
  wshShell.SendKeys "{ENTER}" 

  intCount = intCount + 1
Loop

'Quit
WScript.Quit

Sources:

  • AppActivate: http://ss64.com/vb/appactivate.html
  • SendKeys: http://en.allexperts.com/q/Visual-Basic-1048/2008/10/Press-key-using-vbs.htm