1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29:
| function TfMain.run_application(strStartCommand: string; var iExitCode: integer): boolean; var recProcessInfo: TProcessInformation; dwExitCode: dword; dwWaitHandle: dword; recStartUpInfo: TStartUpInfo; begin dwExitCode := 0; fillchar(recStartUpInfo, sizeof(TStartUpInfo), 0); recStartUpInfo.cb := sizeof(TStartUpInfo); if createprocess(nil, pchar(strStartCommand), nil, nil, TRUE, NORMAL_PRIORITY_CLASS, nil, nil, recStartUpInfo, recProcessInfo) then begin repeat dwWaitHandle := waitforsingleobject(recProcessInfo.hProcess, 100); Application.ProcessMessages; until (dwWaitHandle <> WAIT_TIMEOUT) or Application.Terminated; GetExitCodeProcess(recProcessInfo.hProcess, dwExitCode); iExitCode := dwExitCode; Result := TRUE; end else Result := FALSE; getlasterror; closehandle(recProcessInfo.hProcess); closehandle(recProcessInfo.hThread); end; |