Hi Colin,
 
The following should do what you want.
 

procedure ExecProgram(const ProgName : String; const Wait : Boolean; const Visibility : integer);
var
    StartupInfo              : TStartupInfo;
    ProcessInfo              : TProcessInformation;
    Rslt                     : LONGWORD;
    r                        : boolean;
begin
 FillChar(StartupInfo, sizeof(StartupInfo), 0);
 With StartupInfo Do
     Begin
      cb:= sizeof(StartupInfo);
      dwFlags:= STARTF_USESHOWWINDOW;
      wShowWindow:= Visibility;
     End;
 r:= CreateProcess(Nil, PChar(ProgName), Nil, Nil, False, NORMAL_PRIORITY_CLASS, Nil, Nil, StartupInfo, ProcessInfo);
 If not r then
     Begin
      MessageDlg('Create Process Error', mtError, [mbOk], 0);
      Exit;
     End;
 Application.ProcessMessages;
 If Wait then
     Begin
      Repeat
        WaitforSingleObject(ProcessInfo.hProcess, 100);
        Application.ProcessMessages;
        GetExitCodeProcess(ProcessInfo.hProcess, Rslt);
      Until not (Rslt = STILL_ACTIVE);
     End;
 CloseHandle(ProcessInfo.hProcess);
 CloseHandle(ProcessInfo.hThread);
end;
 
Regards
Steve Galyer
----- Original Message -----
Sent: Tuesday, 27 February 2001 20:01
Subject: [DUG]: Execute and Wait

Hi all,

Some years ago I vaguely remember using a technique to launch another executable program from an application and monitor its operation so that you knew when it had completed, in order to continue with what you were doing.

The basis on which the monitoring was done I seem to remember, was to monitor the instance handle returned from the executing program using the GetModuleUseage function and waiting, whilst handling windows messages, until the instance handle count returned to zero.

Can any of you post me a method based on this principle, or any other that will allow me to start another application from a running program and have it signal back when it's done?

Thanks

Colin

 

Reply via email to