Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cant open my application

Status
Not open for further replies.

hexOffender

Programmer
Nov 6, 2006
146
0
0
US
I have a script that opens first a scaner Application, and when that closes I want to open an app that I wrote in VB.net. here is the script...

set WshShell = Wscript.CreateObject("WScript.Shell")
cmdID = WshShell.run( "FImage.exe" ,9 )
WSHShell.AppActivate( cmdID )
'WshShell.run"FImage.exe" ,9,true
wscript.sleep 100
wshshell.SendKeys "%s"
wshshell.SendKeys "f"
wscript.sleep 50
WshShell.SendKeys "{ENTER}"
wscript.sleep 50
WshShell.SendKeys "{ENTER}"
wscript.sleep 50
wshShell.sendkeys "{TAB}"
wscript.sleep 50
wshShell.sendkeys "{TAB}"
wscript.sleep 50
WshShell.SendKeys "{ENTER}"
wscript.sleep 100
WshShell.sendkeys ("%{F4}")

WshShell.run "C:\Program Files\MWPH\PatientImages\MWPH Patient Images.exe"

Is it because of the spaces in the executable name that it wont open?


 
WshShell.Run """C:\Program Files\MWPH\PatientImages\MWPH Patient Images.exe"""

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
No the first app runs fine, that one gets the sendkeys.
Im talking about the last line in the script..

WshShell.run "C:\Program Files\MWPH\PatientImages\MWPH Patient Images.exe"

this wont open my executable, is it because of the spaces?
 
PHV, thanks that was it...
except now both apps are opening at the same time,
do I have to dispose of the WshShell object and recreate it?
 
Hello,

This is my first post, but I think I can help.

I modified your script just a little bit. I used chr(34) which is a vbscript constant for the quote ". The part that will make the script wait until the other application is the true in the following lines.

**cmdID = WshShell.run( chr(34) & "FImage.exe" & chr(34) ,9, true )**
**returncode = WshShell.run (chr(34) & C:\Program Files\MWPH\PatientImages\MWPH Patient Images.exe" & chr(34),1,True)**
-----
Syntax
WshShell.Run (strCommand, [intWindowStyle], [bWaitOnReturn])
-----

This script should work.

set WshShell = Wscript.CreateObject("WScript.Shell")
cmdID = WshShell.run( chr(34) & "FImage.exe" & chr(34) ,9, true )
WSHShell.AppActivate( cmdID )
WshShell.run"FImage.exe" ,9,true
wscript.sleep 100
wshshell.SendKeys "%s"
wshshell.SendKeys "f"
wscript.sleep 50
WshShell.SendKeys "{ENTER}"
wscript.sleep 50
WshShell.SendKeys "{ENTER}"
wscript.sleep 50
wshShell.sendkeys "{TAB}"
wscript.sleep 50
wshShell.sendkeys "{TAB}"
wscript.sleep 50
WshShell.SendKeys "{ENTER}"
wscript.sleep 100
WshShell.sendkeys ("%{F4}")

returncode = WshShell.run (chr(34) & C:\Program Files\MWPH\PatientImages\MWPH Patient Images.exe" & chr(34),1,True)
 
DTodd83, waiting for FImage termination defeats the SendKeys purpose !
 
This is hexOffender's quote: "except now both apps are opening at the same time, do I have to dispose of the WshShell object and recreate it?"

The f4 will close the other app, then the mwph patient images.exe will open, like it looks like it should.

How does the script work for you, hexOffender?
 
DTodd,
I tried your modifications but it get an error
at line 21 char 39, it looks like its looking for a ')'.
I need for the script to open FImage.exe, run through the SendKeys cmds, then open MWPH Patient Images.exe.

Currently it is opneing FImage.exe then opening MWPH Patient Images.exe, without going through the sendkeys.
 
you can terminate the first app by alt-f4 "%{F4}" then let it settle down wscript.sleep 200
then start the next app. unless when you terminate the first app, you have to press some other keys other than alt-F4!
 
I've tried that too, even setting the sleep to 1000 still wont do what I want.
 
>WSHShell.AppActivate( cmdID )
The problem is that this is not the correct argument for the AppActivate method. You can run the application then call the task manager to read the title of the windows (which is squared localized title). Use that name for the appactivate. If you had had the right syntax for that, at least the 2nd application must run only after all the sleep associated with the sendkeys! As the sendkeys are effectively sent to garbage collector, it gave the apparent effect of both applications running at the same time.
 
Tsuji,
What does this mean? "which is squared localized title"





 
The error on line 21 is because you're missing the " in from of c:. Should read more like this:

Code:
returncode = WshShell.run (chr(34) & "C:\Program Files\MWPH\PatientImages\MWPH Patient Images.exe"  & chr(34),1,True)

Another thing that you may want to look at is this line:
Code:
cmdID = WshShell.run( chr(34) & "FImage.exe" & chr(34) ,9, true )
WSHShell.AppActivate( cmdID )

The AppActivate method of WScript.Shell takes either the Title of the application you want to set focus to or the Process ID and your variable cmdID is not providing any of this information; simply the exit code of the command you just ran.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
haha, looks like tsuji beat me to the punch. The title as it appear in the title bar. It can be exact or partial, though exact is what you should try to go for.

--------------------------------------------------------------------------------
dm4ever
My philosophy: K.I.S.S - Keep It Simple Stupid
 
I meant squared[red]ly[/red] localized, ie, localized to the os language version. If you use english version, don't worry about it. nodepad is still nodepad (rather than some other localized name.)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top