function 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;