Monday, October 22, 2007

Automate applications using VBScript

I have just discovered a nice feature in Windows Script Host; which is the SendKeys method in the WScript.Shell class.

Using this method to send a stream of key strokes to another application would allow for remote automation or (for example) creating application tutorials.

Cut the following code, paste in a text file and give it .vbs extension, double click the file to run it and watch J


Set WshShell = WScript.CreateObject("WScript.Shell")

WshShell.Run "notepad"

WScript.Sleep 100

WshShell.AppActivate "Untitled - Notepad"

WScript.Sleep 100

WshShell.SendKeys "Hello"

No comments: