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