Delphi 使用ShellExecuteEx运行应用程序并等待完成


本文整理自网络,侵删。

 

uses Winapi.ShellAPI;


{ Runs application using ShellExecuteEx and waits for completion. }
function ShellExecuteAndWait(FileName: String; Params: String): Boolean;
var
  exInfo: TShellExecuteInfo;
  Ph: DWORD;
begin
  FillChar(exInfo, SizeOf(exInfo), 0);
  with exInfo do
  begin
    cbSize := SizeOf(exInfo);
    fMask := SEE_MASK_NOCLOSEPROCESS or SEE_MASK_FLAG_DDEWAIT;
    Wnd := GetActiveWindow();
    exInfo.lpVerb := 'open';
    exInfo.lpParameters := PChar(Params);
    lpFile := PChar(FileName);
    nShow := SW_SHOWNORMAL;
  end;
  if ShellExecuteEx(@exInfo) then
    Ph := exInfo.hProcess
  else
  begin
    ShowMessage(SysErrorMessage(GetLastError));
    Result := true;
    exit;
  end;
  while WaitForSingleObject(exInfo.hProcess, 50) <> WAIT_OBJECT_0 do
    Application.ProcessMessages;
  CloseHandle(Ph);
  Result := true;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin

ShellExecuteAndWait('regedit.exe','');

end;

相关阅读 >>

Delphi ip地址转换

Delphi 16进制字符串转原字符串

Delphi 主程序装载脚本

Delphi xe4 for ios 谨慎处理字符串

Delphi 封装的tidhttp get post 请求

Delphi 删除或清空一个目录(包含多级)

Delphi控件安装与删除

Delphi中使用临界区来让线程同步

Delphi编写的android程序获取root权限实现(2015.4.15更新,支持android 4.4)

Delphi2010:把stringgrid数据保存到excel

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



打赏

取消

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

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

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

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

评论

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