Delphi 调用外部程序并等待其运行结束

 
Delphi 调用外部程序并等待其运行结束 



function CreateSingleObject(FileName: string):Boolean;
var
  s: TStartupinfo;
  p: TProcessInformation;
begin
  Result:=False;
  FillChar(s, Sizeof(TStartupinfo), 0);
  s.cb := Sizeof(TStartupinfo);
  if CreateProcess(pChar(FileName), nil, nil, nil, False,
    Normal_Priority_Class, nil, nil, s, p) then
  begin
    WaitforSingleObject(p.hProcess, INFINITE);
    CloseHandle(p.hProcess);
    Result:=True;
  end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
  Hide;
  CreateSingleObject('C:WindowsSystem32cmd.exe');
  BringToFront;
  Show;
end;





原文地址:https://www.cnblogs.com/xe2011/p/3427770.html