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!

ShellExecute and wait for completion

Status
Not open for further replies.

timmappa

Programmer
Jan 21, 2001
20
0
0
AU
I need to launch some process (typically - another EXE) from VFP program, and wait until this process completes before moving to another command in VFP program. I am using ShellExecute command for this. It will not wait at the moment. How can I do ShellExecute command wait until called program finsih processing? Please help. Let me know if any other way i can do this?

DECLARE INTEGER ShellExecute IN shell32.dll ;
INTEGER hndWin, ;
STRING cAction, ;
STRING cFileName, ;
STRING cParams, ;
STRING cDir, ;
INTEGER nShowWin
 
Hi Timmappa,

You've got a couple of options.

The easier is not to use ShellExecute(), but to do something like this instead:

Code:
oWsh = CREATEOBJECT("wscript.shell")
oWsh.Run("Notepad", 3, .T.)

This will run Notepad in a maxmimised window. Substitute your own application name here. It's the third parameter -- the .T. -- that tells it to run modally, that is, your VFP app will suspend until the other app has closed.

The other possibility is to use ShellExecute() and then to start a loop in which you test for the presence of the launched window. For an example of how to do that, see the article Find out what applications are running on the user's system.

Hope this helps.

Mike

__________________________________
Mike Lewis (Edinburgh, Scotland)

My Visual FoxPro site: www.ml-consult.co.uk
 
The biggest task might be for the application to 'know' when the other external application is COMPLETE.

Does the external application do anything special to indicate when it has completed?

If, as Mike has suggested above, the external application will EXIT when complete, the VFP application can loop waiting for the absence of the other application.

Otherwise you will need to find some other means of determining that the other app is done.

Good Luck,
JRB-Bldr




 
Mike’s suggestion is perfect.

oWsh = CREATEOBJECT("wscript.shell")
oWsh.Run("Notepad", 3, .T.)

This works fine. Thanks
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top