您的位置:首页 > 其它

运行程序并等待结束

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;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: