Link to home
Start Free TrialLog in
Avatar of jonnyfive
jonnyfive

asked on

Finding a instance after it is created with ShellExecute

I want to open a DOS Window and execute a DOS program (such as the extract command) using the ShellExceute command. Since the window is hidden, it doesn't have a Window handle. (At least FindWindow can't find it). Is there a way, I can determin that the program is still running? I get a hInstance back from ShellExecute, but I can't find a function that is able to check if it is still vaild. Thanks for help...
Avatar of jonnyfive
jonnyfive

ASKER

Edited text of question
ASKER CERTIFIED SOLUTION
Avatar of Madshi
Madshi

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
I was going to post some code, but Madshi's method is much better than mine.  I will copy his instead!  hehehe :)

Heath
Hi Madshi... Thanks for the fast answer... I just tried the code. The reason why I want to know if the task is still running is simple: I want to wait for the Dos command to be finished before I go on in my program. Your code seems to work also parallel to the main program. What has to be changed to do this?
Thanks, Jonny Five :-)
It works *quite* parallel. The Button1Click procedure does not return until the dos process is finished, but messages are handled nevertheless. If you would not handle messages, it would have strange results. Your main form would not be repainted and such stuff.
I think you should use "enabled:=false" in the beginning of Button1Click and "enabled:=true" at the end of Button1Click. Then the user can't do anything with your form. I think that is exactly what you need...   :-)

Hi Heath, yeah, copy it. I like it if other experts like my sources...  :-)

Regards, Madshi.
After I tested the code a bit more, I think it is a very nice solution to the problem. Thanks... :-)