- 人气:
- 放大
- 缩小
- 二维码
- 赞赏
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;