delphi调用外部EXE,等待执行完毕时再响应后续操作.
2012-11-24 09:37
309 查看
http://blog.csdn.net/gjsshn_2010/article/details/4158360
function RunProcess(FileName: string; ShowCmd: DWORD; wait: Boolean; ProcID: PDWORD): Longword;
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
FillChar(StartupInfo, SizeOf(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
StartupInfo.wShowWindow := ShowCmd;
if not CreateProcess(nil,@Filename[1], nil, nil, False, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo,ProcessInfo)
then
Result := WAIT_FAILED
else
begin
if wait = FALSE then
begin
if ProcID <> nil then
ProcID^ := ProcessInfo.dwProcessId;
result := WAIT_FAILED;
exit;
end;
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
end;
if ProcessInfo.hProcess <> 0 then
CloseHandle(ProcessInfo.hProcess);
if ProcessInfo.hThread <> 0 then
CloseHandle(ProcessInfo.hThread);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ProcID: Cardinal;
begin
ProcID := 0;
if OpenDialog1.Execute then
RunProcess(OpenDialog1.FileName, SW_SHOW, CheckBox1.Checked, @ProcID);
ShowMessage(IntToStr(ProcID));
end;
function RunProcess(FileName: string; ShowCmd: DWORD; wait: Boolean; ProcID: PDWORD): Longword;
var
StartupInfo: TStartupInfo;
ProcessInfo: TProcessInformation;
begin
FillChar(StartupInfo, SizeOf(StartupInfo), #0);
StartupInfo.cb := SizeOf(StartupInfo);
StartupInfo.dwFlags := STARTF_USESHOWWINDOW or STARTF_FORCEONFEEDBACK;
StartupInfo.wShowWindow := ShowCmd;
if not CreateProcess(nil,@Filename[1], nil, nil, False, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo,ProcessInfo)
then
Result := WAIT_FAILED
else
begin
if wait = FALSE then
begin
if ProcID <> nil then
ProcID^ := ProcessInfo.dwProcessId;
result := WAIT_FAILED;
exit;
end;
WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
GetExitCodeProcess(ProcessInfo.hProcess, Result);
end;
if ProcessInfo.hProcess <> 0 then
CloseHandle(ProcessInfo.hProcess);
if ProcessInfo.hThread <> 0 then
CloseHandle(ProcessInfo.hThread);
end;
procedure TForm1.Button1Click(Sender: TObject);
var
ProcID: Cardinal;
begin
ProcID := 0;
if OpenDialog1.Execute then
RunProcess(OpenDialog1.FileName, SW_SHOW, CheckBox1.Checked, @ProcID);
ShowMessage(IntToStr(ProcID));
end;
相关文章推荐
- delphi调用外部EXE,等待执行完毕时再响应后续操作.
- winform c#调用外部EXE程序,并等待外部EXE程序执行完毕才执行下面的代码的方法。
- vc调用EXE文件,并且等待其执行完毕.
- C++ 调用exe,可等待调用的exe执行完毕后才继续执行父进程 CreateProcess
- C#winform调用外部程序,等待外部程序执行完毕才执行下面代码
- 让Delphi使用带参数来调用外部可执行文件(EXE文件)
- delphi 调用外部exe ,并等待调用程序运行结束
- 如何让Delphi调用外部程序并等待其运行信息(如结束)
- 日积月累:Java等待子线程执行完毕,再执行后续逻辑
- delphi执行一个外部程序,当外部程序结束后,delphi程序立即响应
- WCF热门问题编程示例(2)多个实例调用一个WCF服务操作,需要等待服务响应吗
- c# 使用Process调用外部程序时等待该进程结束后再执行住进程
- WCF热门问题编程示例(2)多个实例调用一个WCF服务操作,需要等待服务响应吗
- VFP调用外部Exe文件,执行完后,再接着执行本程序(经典转载)
- C#程序调用Delphi可执行EXE文件过程
- Delphi 调用外部程序并等待其运行结束
- vc++调用外部可执行程序例子——调用ffmpeg.exe
- Delphi调用外部程序并等待其运行结束
- delphi执行一个外部程序,当外部程序结束后,delphi程序立即响应
- C/C++执行外部程序(调用外部exe程序)