Link to home
Start Free TrialLog in
Avatar of SeltzerWater
SeltzerWater

asked on

Sendkeys in VBscript not working

I am trying to automate a scanning application for some users.
I thought this would be simple, but its not working.
All I need to do is open the app, send ALT+s and then ALT+F, and then two {ENTER} keys.

here is what I have so far...

set WshShell = Wscript.CreateObject("WScript.Shell")
WshShell.run"FImage.exe" ,3,true
WSHShell.AppActivate "FImage"
wscript.sleep 200
wshshell.SendKeys "%s"
wscript.sleep 100
wshshell.SendKeys "%f"
wscript.sleep 100
WshShell.SendKeys "{ENTER}"

After the app opens, it just sits there, the ALT+ S does not open the Menuitem.
Does the .AppActivate use the name of the executibale or something else?
Avatar of dave_moats
dave_moats

You may want to pass the handle to the executable you created to the AppActivate call.

cmdID = WshShell.run( "FImage.exe" ,3,true )
WSHShell.AppActivate( cmdID )

When you call ALT-S are you tring to open the file menu and save the file contents?  If so, you might want to try:

wscript.sleep 200
wshshell.SendKeys "%f"
wscript.sleep 100
wshshell.SendKeys "s"
wscript.sleep 100
WshShell.SendKeys "{ENTER}"
WshShell.SendKeys "{ENTER}"

If that is not the case what does ALT-S do in your application?

Dave
ASKER CERTIFIED SOLUTION
Avatar of dave_moats
dave_moats

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of SeltzerWater

ASKER

Im trying to open the "Scan" menu item, and then the "scan to File" item.
I just tried your suggestion, but nothing. I am noticing, however that after I close the scanning application, the ALT + F is being sent to IE and the IE File menu is appearing.
Dave you were right,
when I took out the "true" it worked.
I know this is old but you can also use "~" at the end of your string to ENTER
Example below is to run calc.exe as another user. Very useful if you need regular users to run applications that require admin rights.

Set oShell = WScript.CreateObject("WScript.Shell")
oShell.Run "C:\Windows\System32\RunAs.exe /user:card\someuser ""C:\Windows\System32\Calc.exe"
WScript.Sleep 1000
oShell.SendKeys "somepassword~"