这个够了。
{****************************************}
{执行其他可执行程序,等待它执行完毕再继续执行自己,否则阻塞}
{****************************************}
function TFrm1.ExecAndWait(const Filename, Params: string; WindowState: word): boolean;
var SUInfo: TStartupInfo;
ProcInfo: TProcessInformation;
CmdLine: string;
begin
CmdLine := '"' + Filename + '"' + Params; { 注意检查长文件名}
FillChar(SUInfo, SizeOf(SUInfo), #0);
with SUInfo do begin
cb := SizeOf(SUInfo);
dwFlags := STARTF_USESHOWWINDOW;
wShowWindow := WindowState;
end;
Result := CreateProcess(NIL, PChar(CmdLine), NIL, NIL,
FALSE,CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, NIL,
PChar(ExtractFilePath(Filename)), SUInfo, ProcInfo);
if Result then {等待结束 }
begin
WaitForSingleObject(ProcInfo.hProcess, INFINITE);
CloseHandle(ProcInfo.hProcess); {清理句柄 }
CloseHandle(ProcInfo.hThread);
end;
end;