Board index » delphi » program termination?

program termination?

Greetings,

i am scheduling a executable file with the

PGMHandle:=ShellExecute(0,'open',PChar(PNamePath),PChar(Parameter),nil,sw_sh
ow);
command and the application runs well but.......

how can i check if the application is still running because
neither
  waitforsingleobject(PGMHandle,infinite);
nor
  GetExitCodeProcess(PGMHandle,TermSts);
are working properly

Thanks
Bernd
planetmas...@masters-burghausen.de

 

Re:program termination?


Hi Bernd,

I think you should use CreateProcess() instead of ShellExecute. Try:

  procedure ExecAndWaitForClose;

  var
    S_Info: TStartupInfo;
    P_Info: TProcessInformation;

  begin
    with S_Info do
    begin
      cb:=SizeOf(S_Info);
      ....
        [other values]
      ....
    end;

    if CreateProcess(PChar(YourAppName),PChar(YourCmdLine),nil,nil,
      False,CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS,nil,nil,
      S_Info,P_Info)=True then
    begin
      WaitforSingleObject(P_Info.hProcess,INFINITE);
    end;
  end;

You could change it into a function, returning the process termination
status (after WaitForSingleObject):

  GetExitCodeProcess(P_Info.hProcess,Result);

Good luck,
Sasan.

Quote
PlanetMaster wrote:

> Greetings,

> i am scheduling a executable file with the

> PGMHandle:=ShellExecute(0,'open',PChar(PNamePath),PChar(Parameter),nil,sw_sh
> ow);
> command and the application runs well but.......

> how can i check if the application is still running because
> neither
>   waitforsingleobject(PGMHandle,infinite);
> nor
>   GetExitCodeProcess(PGMHandle,TermSts);
> are working properly

> Thanks
> Bernd
> planetmas...@masters-burghausen.de

Re:program termination?


Have you tried -

Repeat
    Application.ProcessMessages;
    Until Application.Terminated or (GetModuleUsage(PGMHandle) = 0);

Gary

Quote
PlanetMaster wrote in message <76a7ua$ob...@goof.de.uu.net>...
>Greetings,

>i am scheduling a executable file with the

>PGMHandle:=ShellExecute(0,'open',PChar(PNamePath),PChar(Parameter),nil,sw_s
h
>ow);
>command and the application runs well but.......

>how can i check if the application is still running because
>neither
>  waitforsingleobject(PGMHandle,infinite);
>nor
>  GetExitCodeProcess(PGMHandle,TermSts);
>are working properly

>Thanks
>Bernd
>planetmas...@masters-burghausen.de

Other Threads