本文整理自网络,侵删。
function ExecAndWait(sExe, sCommandLine: string): Boolean;var dwExitCode: DWORD; tpiProcess: TProcessInformation; tsiStartup: TStartupInfo;
begin Result := False; FillChar(tsiStartup, SizeOf(TStartupInfo), 0); tsiStartup.cb := SizeOf(TStartupInfo); if CreateProcess(PChar(sExe), PChar(sCommandLine), nil, nil, False, 0, nil, nil, tsiStartup, tpiProcess) then begin if WAIT_OBJECT_0 = WaitForSingleObject(tpiProcess.hProcess, INFINITE) then begin if GetExitCodeProcess(tpiProcess.hProcess, dwExitCode) then begin if dwExitCode = 0 then Result := True else SetLastError(dwExitCode + $2000); end; end; dwExitCode := GetLastError; CloseHandle(tpiProcess.hProcess); CloseHandle(tpiProcess.hThread); SetLastError(dwExitCode); end;end;
procedure TForm2.Button1Click(Sender: TObject);
beginExecAndWait('123.exe','');end;
相关阅读 >>
Delphi android实例-读取设备联系人(xe8+小米2)
更多相关阅读请进入《Delphi》频道 >>