运行程序并等待结束
2009-12-27 13:37
351 查看
function ExecAndWait(aFilename: string; aParamStr: string = '';
aWait: boolean = True): boolean;
var
si: TStartupInfo;
pi: TProcessInformation;
begin
if not FileExists(aFilename) then
Result := False
else
begin
FillChar(pi, SizeOf(TProcessInformation), #0);
FillChar(si, SizeOf(TStartupInfo), #0);
with si do
begin
cb := SizeOf(TStartupInfo);
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := SW_SHOW;
end;
Result := CreateProcess(PChar(aFilename), PChar(aParamStr), nil, nil,
False, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil,
PChar(ExtractFilePath(aFilename)), si, pi);
if Result and aWait then
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
end;
end;
aWait: boolean = True): boolean;
var
si: TStartupInfo;
pi: TProcessInformation;
begin
if not FileExists(aFilename) then
Result := False
else
begin
FillChar(pi, SizeOf(TProcessInformation), #0);
FillChar(si, SizeOf(TStartupInfo), #0);
with si do
begin
cb := SizeOf(TStartupInfo);
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := SW_SHOW;
end;
Result := CreateProcess(PChar(aFilename), PChar(aParamStr), nil, nil,
False, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil,
PChar(ExtractFilePath(aFilename)), si, pi);
if Result and aWait then
WaitForSingleObject(pi.hProcess, INFINITE);
CloseHandle(pi.hProcess);
CloseHandle(pi.hThread);
end;
end;
相关文章推荐
- Delphi 调用外部程序并等待其运行结束
- VC启动一个程序并等待运行结束
- Delphi 调用外部程序并等待其运行结束
- 等待外部程序运行结束以后 主程序再继续运行
- windows运行一个程序并等待其结束。
- 等待程序运行结束
- [VB]VB启动/结束另一程序(Shell 等待程序运行结束)
- VB Shell调用后 等待程序运行结束
- delphi 调用外部exe ,并等待调用程序运行结束
- [delphi]调用外部程序并等待其运行结束
- Delphi调用外部程序并等待其运行结束
- VB Shell调用后 等待程序运行结束
- 【vs2015】C++ 程序运行并等待进程结束
- MFC调用exe程序,并等待exe程序运行结束(ShellExecuteEx)
- MFC调用exe程序,并等待exe程序运行结束(ShellExecuteEx)
- Delphi 调用外部程序并等待其运行结束
- VB Shell调用后 等待程序运行结束
- 如何让Delphi调用外部程序并等待其运行结束
- 如何调用一个程序,等待运行结束,并知晓程序运行成功与否:ShellExecuteEx;WaitForSingleObject;GetExitCodeProcess(C代码)
- 调用外部程序并等待其运行结束/实例为调用QQ截图