Board index » delphi » winexec (and wait for an end of the started application)

winexec (and wait for an end of the started application)

The following problem I have to solve:

I start from within a Delphi-App a Dos-Programm.
After starting it with WinExec the Delphi-Programm should wait until
the Dos-Prog. is ended.

Can anyone give me a hint on how to do so ?

tia
Hans-Juergen Lommel

 

Re:winexec (and wait for an end of the started application)


Use CreateProcess and WaitForSingleObject instead.

Quote
<lom...@uni-duesseldorf.de> wrote in message

news:378e2992.6718781@news.rz.uni-duesseldorf.de...
Quote
> The following problem I have to solve:

> I start from within a Delphi-App a Dos-Programm.
> After starting it with WinExec the Delphi-Programm should wait until
> the Dos-Prog. is ended.

> Can anyone give me a hint on how to do so ?

> tia
> Hans-Juergen Lommel

Re:winexec (and wait for an end of the started application)


Quote
lom...@uni-duesseldorf.de wrote:

> I start from within a Delphi-App a Dos-Programm.
> After starting it with WinExec the Delphi-Programm should wait until
> the Dos-Prog. is ended.

> Can anyone give me a hint on how to do so ?

I Saw something in here, in Examples section, some time ago.
Not tested, no quarantee there will be anything useful.
http://www.delphifreestuff.com/

Markku Nevalainen

Re:winexec (and wait for an end of the started application)


Quote
On Thu, 15 Jul 1999 18:37:43 GMT, lom...@uni-duesseldorf.de wrote:
>The following problem I have to solve:

>I start from within a Delphi-App a Dos-Programm.
>After starting it with WinExec the Delphi-Programm should wait until
>the Dos-Prog. is ended.

>Can anyone give me a hint on how to do so ?

use this function:

function TForm1.WinExecAndWait32(FileName:String;
Visibility:integer):integer;
var
  zAppName:array[0..512] of char;
  zCurDir:array[0..255] of char;
  WorkDir:String;
  StartupInfo:TStartupInfo;
  ProcessInfo:TProcessInformation;
  Resultado: DWord;
begin
  StrPCopy(zAppName,FileName);
  GetDir(0,WorkDir);
  StrPCopy(zCurDir,WorkDir);
  FillChar(StartupInfo,Sizeof(StartupInfo),#0);
  StartupInfo.cb := Sizeof(StartupInfo);

  StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
  StartupInfo.wShowWindow := Visibility;
  if not CreateProcess(nil,
    zAppName,                      { pointer to command line string }
    nil,                           { pointer to process security
attributes}
    nil,                           { pointer to thread security
attributes}
    false,                         { handle inheritance flag }
    CREATE_NEW_CONSOLE or          { creation flags }
    NORMAL_PRIORITY_CLASS,
    nil,                           { pointer to new environment block

Quote
}

    nil,                           { pointer to current directory name
Quote
}

    StartupInfo,                   { pointer to STARTUPINFO }
    ProcessInfo) then Result := -1 { pointer to PROCESS_INF }

  else begin
    WaitforSingleObject(ProcessInfo.hProcess,INFINITE);
    GetExitCodeProcess(ProcessInfo.hProcess,Resultado);
    Result := Resultado;
  end;
end;

This and other Delphi tips in www.q3.nu/trucomania

Un Saludo:
        Q3 Team

Other Threads