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: 30: 31: 32: 33: 34: 35:
| procedure ExecuteFile(const AFilename: string; AParameter, ACurrentDir: string; AWait: Boolean); var si: TStartupInfo; pi: TProcessInformation; begin if Length(ACurrentDir) = 0 then begin ACurrentDir := ExtractFilePath(AFilename); if ACurrentDir[Length(ACurrentDir)] = '' then Delete(ACurrentDir, Length(ACurrentDir), 1); end; FillChar(si, SizeOf(si), 0); with si do begin cb := SizeOf(si); dwFlags := STARTF_USESHOWWINDOW; wShowWindow := SW_NORMAL; end; FillChar(pi, SizeOf(pi), 0); if Length(AParameter) = 0 then AParameter := Format('"%s"', [AFilename]) else AParameter := Format('"%s" "%s"', [AFilename, AParameter]); if CreateProcess(nil, PChar(AParameter), nil, nil, False, CREATE_DEFAULT_ERROR_MODE or CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, PChar(ACurrentDir), si, pi) then begin try if AWait then WaitForSingleObject(pi.hProcess, INFINITE); finally CloseHandle(pi.hProcess); CloseHandle(pi.hThread); end; end; end; |