doomgod

Exec and wait

Apr 26th, 2013
167
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 0.57 KB | None | 0 0
  1. function ExecAndWait(Path: string; Wait: boolean; Window: word): integer;
  2. var
  3.   si: TStartupInfo;
  4.   p:  TProcessInformation;
  5.   RetCode: DWord absolute result;
  6. begin
  7.   FillChar(Si,SizeOf(Si),0);
  8.   with Si do begin
  9.     cb := SizeOf( Si);
  10.     dwFlags := startf_UseShowWindow;
  11.     wShowWindow := Window;
  12.   end;
  13.   Createprocess(nil,pChar(Path),nil,nil,false, Create_default_error_mode,nil,nil,si,p);
  14.   result:= p.hProcess;
  15.   if Wait then begin
  16.     Waitforsingleobject(p.hProcess,infinite);
  17.     if not GetExitCodeProcess(p.hProcess, RetCode) then result:= -1;
  18.   end;
  19. end;
Advertisement
Add Comment
Please, Sign In to add comment