?
Solved

VBScript sendkeys to automate legacy DOS app

Posted on 2007-07-20
9
Medium Priority
?
3,428 Views
Last Modified: 2012-08-13
We run an old clipper application through DOS.  It's fast and easy to use and does almost everything we need it to do.  The one problem I have is running the regular maintenance through the application.  It has no scheduler or outside processes we can run on a schedule.  I was trying to write a vbs that would send the keystrokes to the application, but it doesn't seem to work.  I tried in both command.com and cmd.exe.  It will open the DOS window and in cmd will actually launch the application.  In command, it only sits at the default prompt.  The below is me just trying to open the app, then exit.  Any ideas on how to send the keys to these legacy apps in winXP?

Option Explicit
Dim objShell, intWait, wsh
Set objShell = CreateObject("WScript.Shell")
Set wsh = CreateObject("Shell.Application")
wsh.FileRun
intWait = 1000

With objshell
      WScript.Sleep intWait
      .SendKeys "cmd~"
      WScript.Sleep intWait
      .SendKeys "f:~"
      WScript.Sleep intWait
      .sendkeys "app~"
      .SendKeys "{ESC}"
      .SendKeys "exit~"
End With

WScript.Quit
0
Comment
Question by:traigo
9 Comments
 
LVL 38

Expert Comment

by:PaulHews
ID: 19534396
This example shows how to launch a process, and write to StdIn to send commands to it.

http://msdn2.microsoft.com/en-US/library/yzzwsz3t.aspx
0
 
LVL 19

Expert Comment

by:William Elliott
ID: 19536371


Option Explicit
Dim objShell, intWait, wsh, app
intWait = 1000
set objShell = CreateObject("WScript.Shell")

app = "something.exe"


objShell.Run("cmd")
WScript.Sleep intWait
'objShell.SendKeys "cmd~"
WScript.Sleep intWait
objShell.SendKeys "f:\" & app & "~"
WScript.Sleep intWait
objShell.SendKeys "{ESC}~"
WScript.Sleep intWait
objShell.SendKeys "exit~"
WScript.Quit
0
 
LVL 19

Expert Comment

by:William Elliott
ID: 19536373
you can't use the with because it would do this
objshell.WScript.Sleep intWait

and that doesn't work
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
LVL 25

Expert Comment

by:Ron Malmstead
ID: 19549864
Set WshShell = Wscript.CreateObject("Wscript.Shell")
CMD1 = WshShell.Run("cmd /c f:\application.exe")
Wscript.Sleep 2000
WshShell.AppActivate(CMD1)
WshShell.SendKeys "{ESC}"
WshShell.SendKeys "QUIT~"
0
 

Author Comment

by:traigo
ID: 19557280
I've tried everything.  I still get the same results or I get an error.  I couldn't get the StdIn to do anything except error.
0
 
LVL 19

Expert Comment

by:William Elliott
ID: 19560907
you can use autoit to do it. it will take some playing though.
http://www.autoitscript.com/autoit3/docs/functions/Send.htm

i'm sure you will have to use the winactivate a few times within the script to make sure the dos window is active, then utilize the time delays
0
 

Author Comment

by:traigo
ID: 19655842
I haven't had any luck with autoit.  Not sure if this is even possible on this old app.  Any other suggestions?
0
 
LVL 19

Accepted Solution

by:
William Elliott earned 2000 total points
ID: 19657927
some options?
http://techsupt.winbatch.com/TS/T000001058F28.html

or you can try the autoit approach here is an example script
save as something.au3


$app = "c:\yourprogram.exe"
run("cmd")
sleep(2000)
WinActivate("C:\WINDOWS\system32\cmd.exe", "")
Send( "Title = Customrun{ENTER}")
sleep(1500)
WinActivate("Customrun")
Send( "f:\" & $app & "{ENTER}")
sleep(3000)
Send("{ESC}{Enter}")
sleep(1500)
Send("echo hi i'm a script{ENTER}")
sleep(2500)
Send("exit{ENTER}")
0
 

Author Comment

by:traigo
ID: 19691978
Thanks weellio!  That worked with a little adjustment to fit my program.  I am able to navigate using the send function.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month8 days, 19 hours left to enroll

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question