Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there a way to determine an app is running ?
Message
From
22/01/2001 13:20:24
 
 
To
22/01/2001 02:42:38
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00466291
Message ID:
00466782
Views:
10
>Ed,
>According to docs too CreateProcess() should be able to identify termination of an app. But I mean not just an app, a particular instance of an app. Say you fire 4 instances of word in different VFP sessions and want to wait for termination of particular instances in each. I can't do this now. The first instance waits for termination of all word instances while others immediately return as if word finished. All word instances have the same process id.
>Api_apprun too immediately returns if before a word session is active (user opened word by himself).
>IOW I'm after something that uniqely identifies an app session. Here Hwnd seems to be the only unique thing. Do you know a way of getting Hwnd through CreateProcess() or ShellExecute() launched app instance ? Currently I think to collect all top level windows before and after launch (with the risk another app might be launched in between). Is there a better way ? TIA

CreateProcess() returns a ThreadID, which can be used to enumerate the set of Windows owned by the thread, but it requires a callback, so pure VFP implementation is ruled out.

CreateProcess() should create a new instance of Word, not just DDE-up another thread like ShellExecutge() or ShellExecuteEx(). THe new process is distinct from the running instance of Word, and API_APPRUN's LaunchAppAndWait() should remain running as long as this process and any of it's threads are alive. You can't use ShellExecute() the way you'd like to.

>Cetin
>
>
>
>>>Without knowing its window title.
>>>To my understanding if you can't get a Hwnd you can't determine if an app is finished or not. I hope to be mistaken of course :)
>>>If this is true how could I get a Hwnd to an app I launch with either CreateProcess or ShellExecute (preferably ShellExecute).
>>>What I basically want to do is :
>>>
>>
>>CreateProcess() can identify termination of an app without an hWnd by waiting of the Process Handle to become signalled. This is what API_APPRUN does.
>>
>>ShellExecute() provides no mechanism to determine whether an app terminates. You have to do a FindWindow() and wait for it to go away to determine termination.
>>
>>There is a variant of ShellExecute() called ShellExecuteEx() that hands back a processid, which can be used to get a process handle. Unfortunately, if the ShellExecuteEx() initiates a session using DDE, no ProcessID is returned, so no process handle can be retrieved. and you're back to FindWindow(), which means you're sunk.
>>
>>You have to explicitly use CreateProcess() and wait on the Process Handle to signal to detect termination. With Windows, it's possible to finish editing an object in an MDI app, leave the app running but shut the document, and never terminate, so you're screwed again.
>>
>>I covered someone else's attempt to use Wscript.Shell to launch a document, which relies on ShellExecuteEx(), which results in an OLE error if another session of the app is open, and an indefinite wait state if the document is closed by Word is left running. He claimed that this is not the case, I can demonstrate the failure easily enough.
>>
>>>Launch the app
>>>Wait for it to finish
>>>Return
>>>
>>>I tried :
>>>CreateProcess
>>>WaitForSingleObject
>>>
>>
>>Any time an MDI app is involved, you're basically sunk. You might experiement with watching for the thread handle rather than the process handle to terminate, but I'm not certain that MDI WIndows run as independent threads in a single process. Repeated using of FindWindow() is not a solution, because the caption of the MDI window is not fixed.
>>
>>>However if say already there are 2 instances of Word, launching Word with this just returns immediately. Also GetExitCodeProcess shows only one instance as STILL_ACTIVE.
EMail: EdR@edrauh.com
"See, the sun is going down..."
"No, the horizon is moving up!"
- Firesign Theater


NT and Win2K FAQ .. cWashington WSH/ADSI/WMI site
MS WSH site ........... WSH FAQ Site
Wrox Press .............. Win32 Scripting Journal
eSolutions Services, LLC

The Surgeon General has determined that prolonged exposure to the Windows Script Host may be addictive to laboratory mice and codemonkeys
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform