Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to wait for completion of shellexec ?
Message
From
09/01/2003 11:44:04
 
 
To
09/01/2003 06:51:10
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00739175
Message ID:
00739834
Views:
26
>>>>Is there a way to have foxpro waiting for the end of the execution of a program called with shellexec ?
>>>>
>>>>Thanks
>>>>Eric
>>>
>>
>>>No way <s>. If your app is a single instance on a given computer then you could use Ed Rauh's (rest in peace my friend) Api_Apprun from download's section. Otherwise no alternative that I could find. See thread #738764 for some details.
>>>Cetin
>>
>>Cetin,
>>Actually there is a way to wait. It using the same function (WaitForSingleObject), but it's little bit dirty way. CreateProcess or WScript is the prefer method to launch an app and wait.
>>
>>I can post the code if you still want it :)
>>Regards
>

>Herman,
>Did you really read the thread #738764 ? If you did and saying really WaitForSingleObject waits pls help me with details. I'm trying to make it work for a long time.
>
>"CreateProcess or WScript is the prefer method to launch an app and wait" ???
>What does CreateProcess offer for to wait ? I couldn't see such a parameter. AFAIK after CreateProcess you still need WaitForSingleObject.
>WScript - Does it do it differently or is a wrapper to WinAPI calls ?
>Cetin

Yes, I read the thread already. But after I read all, I can't really follow what you are after. I just took the whole point of your thread that you are trying to make a tracker (like Spy). Eventhough maybe I had some idea but I'm not sure whether it will help or not. So I don't want to jump into the thread.

The reason I replied into this thread is because of the title. If you only want to use ShellExecute and wait for it to finish, I have a solution for this. But as I mentioned it's *dirty*. And it won't work if the created window is hidden (need another solution)

Yes, CreateProcess use WaitForSingleObject (WFSO) to wait and that's what I meant on the first line. What I mean is you can also use the WFSO for ShellExecute.
I prefer CreateProcess is because it's already provided the process handle (not provided with ShellExecute) to use in the WFSO so I consider it as *clean* method.
And WScript is Windows Script Host. I am sorry for my language. My english is not good :)

Anyway, here is the detail:
**** dirty part
- Setforegroundwindow into VFP main window.
- ShellExecute
- Make a tight loop on Getforegroundwindow as long as the return handle is same with VFP main window.
*****
- Get process ID from the return window handle
- Open the process (synchronize) from the process ID
- WFSO

HTH
Herman
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform