启动进程并等待进程结束

  procedure xxxx;
  var
    ShExecInfo: SHELLEXECUTEINFO;
    WaitResult: DWORD;
    APath:string;
  begin      

    APath := ExtractFilePath(ParamStr(0))+'xxx.exe';

    ShExecInfo.cbSize := sizeof(SHELLEXECUTEINFO);
    ShExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS ;
    ShExecInfo.wnd := 0;
    ShExecInfo.lpVerb := nil;
    ShExecInfo.lpFile := pChar(APath); //can be a file as well
    ShExecInfo.lpDirectory := '';
    ShExecInfo.nShow := SW_HIDE;
    ShExecInfo.hInstApp := 0;   
    ShellExecuteEx(@ShExecInfo);
    if (ShExecInfo.hProcess <> 0) then
    begin
      repeat
        WaitResult := WaitForSingleObject(ShExecInfo.hProcess, 100);
      until WaitResult <> WAIT_TIMEOUT;
      ShExecInfo.hProcess := 0;
    end;
  end;

你可能感兴趣的:(启动进程并等待进程结束)