doomgod icon

Exec and wait

doomgod | PRO | 04/26/13 01:36:17 PM UTC | 0 ⭐ | 427 👁️ | Never ⏰ | []
Delphi |

570 B

|

None

|

0 👍

/

0 👎

function ExecAndWait(Path: string; Wait: boolean; Window: word): integer;
var
  si: TStartupInfo;
  p:  TProcessInformation;
  RetCode: DWord absolute result;
begin
  FillChar(Si,SizeOf(Si),0);
  with Si do begin
    cb := SizeOf( Si);
    dwFlags := startf_UseShowWindow;
    wShowWindow := Window;
  end;
  Createprocess(nil,pChar(Path),nil,nil,false, Create_default_error_mode,nil,nil,si,p);
  result:= p.hProcess;
  if Wait then begin
    Waitforsingleobject(p.hProcess,infinite);
    if not GetExitCodeProcess(p.hProcess, RetCode) then result:= -1;
  end;
end;

Comments