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判断字符串是否为数字

Delphi实现抓屏压缩并保存桌面图片

Delphi防止因系统崩溃而丢失任务栏的图标(重建托盘图标)

Delphi xe7 取得进程占用内存的两个函数

Delphi winapi: movewindow - 改变窗口的位置与大小

Delphi高亮显示trichedit当前行

Delphi ifileoperation替换shfileoperation

Delphi版插apc杀进程驱动源码

Delphi isdirectory 判断是否是目录

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



打赏

取消

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

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

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

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

评论

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