If you know the process handle you can execute the following call:

WaitForSingleObject(hProcess,0)
which will return immediately - you can also pass INFINITE which will wait
(and stop your program) until the process terminates.

Your example would then look something like:
while WaitForSingleObject(hProcess,0) <> WAIT_OBJECT_0 do
 Application.ProcessMessages;

Note you would use CreateProcess to get the process handle instead of
WinExec.

There are a couple of freeware components you could also use.

TAppRunner by Jan Goyvaerts
http://www.jgsoft.com/vcl.shtml

TAppExec by CycoCrew
http://myweb.worldnet.net/~cycocrew/delphi/components.html

============================================
Views contained in this post are my personal opinions and unless otherwise
stated not those of any organisation I am associated with.
----------------------------------------------------------------------------
----------
Patrick Dunford, ChristChurch, NZ
http://patrick.dunford.com/


> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]On
> Behalf Of Geoff Jenkins
> Sent: Monday, 1 February 1999 11:23
> To: Multiple recipients of list delphi
> Subject: [DUG]: Detecting a WinExec program terminating
>
>
> I am upgrading a Delphi 1 app to D4 and need to know when an
> outside program
> has finished.
>
> My code snippet was -
>
>   ProgramHandle := WinExec(Batch,sw_ShowMaximized);
>   ...
>   ...
>     while GetModuleUsage(ProgramHandle) <> 0     {wait till program
> terminated before continuing}
>       do Application.processmessages;
>
> - but GetModuleUsage has been long forgotten in the help and I don't know
> how to replace it.

---------------------------------------------------------------------------
    New Zealand Delphi Users group - Delphi List - [EMAIL PROTECTED]
                  Website: http://www.delphi.org.nz

Reply via email to