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;
运行程序并等待结束
最新推荐文章于 2017-11-02 14:32:48 发布