Delphi ExecuteWait运行一个程序等待其结束


本文整理自网络,侵删。

 
     //ShellAPI
procedure ExecuteWait(const sProgramm: string; const sParams: string = ''; fHide: Boolean = false);
    var
      ShExecInfo: TShellExecuteInfo;
    begin
      FillChar(ShExecInfo, sizeof(ShExecInfo), 0);
      with ShExecInfo do
      begin
        cbSize := sizeof(ShExecInfo);
        fMask := SEE_MASK_NOCLOSEPROCESS;
        lpFile := PChar(sProgramm);
        lpParameters := PChar(sParams);
        lpVerb := 'open';
        if (not fHide) then
          nShow := SW_SHOW
        else
          nShow := SW_HIDE
      end;
      if (ShellExecuteEx(@ShExecInfo) and (ShExecInfo.hProcess <> 0)) then
        try
          WaitForSingleObject(ShExecInfo.hProcess, INFINITE)
        finally
          CloseHandle(ShExecInfo.hProcess);
        end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
ExecuteWait('cmd.exe','',false);
end;

相关阅读 >>

Delphi 如何把字符串覆给数组

Delphi tdatetime 日期时间值的比较

Delphi更改android亮度

Delphi xe10.2 firedac 三种连接

Delphi 以系统权限运行程序的代码

Delphi获取flash文件的影片时长,原始尺寸,帧数等信息

Delphi10.3 创建一条json数据

Delphi获得硬盘所有分区

Delphi 获取 cpu 使用率的单元

Delphi adoquery判断插入的值是否重复

更多相关阅读请进入《Delphi》频道 >>



打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...