community.borland.com

Article #16010: WinExecAndWait

 Technical Information Database

TI1010D.txt   WinExecAndWait
Category   :Windows API
Platform    :All
Product    :Delphi  1.0

Description:
Q:  How do I execute a program and have my code wait until it is finished?

A:

uses Wintypes,WinProcs,Toolhelp,Classes,Forms;

Function WinExecAndWait(Path : string; Visibility : word) : word;
var
  InstanceID : THandle;
  PathLen : integer;
begin
  { inplace conversion of a String to a PChar }
  PathLen := Length(Path);
  Move(Path[1],Path[0],PathLen);
  Path[PathLen] := #0;
  { Try to run the application }
  InstanceID := WinExec(
Path,Visibility);
  if InstanceID < 32 then { a value less than 32 indicates an Exec error }
     WinExecAndWait := InstanceID
  else 
  begin
    Repeat
      Application.ProcessMessages;
    until Application.Terminated or (GetModuleUsage(InstanceID) = 0);
    WinExecAndWait := 32;
  end;
end;



Reference:


7/16/98 4:33:59 PM
 

Last Modified: 01-SEP-99