All Forums >> [Scripting] >> WSH & Client Side VBScript >> Open application and execute commands Do you like VisualBasicScript.com? Link to us and help spread the word about our forum. Thanks!
What I'm trying to do is use WSH to open a windows application, perform commands (such as open file, type text into the file, save file as, etc.). I'm starting with notepad which there seem to be a lot of examples for. Here is the first script:
'VBScript Example Set WshShell = WScript.CreateObject("WScript.Shell")
I am expecting that this script will open notepad, activate the notepad window, and then type "Bok", press return and then save the file. Well the script types bok and enter, but doesn't save the file. Is there some other way of doing this, and controlling the commands of windows applications in general? What I'd really like to learn is how to open any windows program and execute commands in it.
If you enter the commands with your keyboard, does it work ? I have first to open the file menue by means of ALT, etcetera, before I can give the save command. It is advisable to give each sendkeys command some time to work, for instance "WScript.Sleep 200" between the lines.
Anyway, the use of sendkeys can be dangerous if multiple windows are open. Sometimes the commands can go to the wrong window causing "unpleasant" results.