Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Is there a way to determine an app is running ?
Message
From
20/01/2001 19:31:09
 
 
To
20/01/2001 18:59:44
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Windows API functions
Miscellaneous
Thread ID:
00466291
Message ID:
00466293
Views:
10
>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