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:\Windows\System32\cmd.exe');
  BringToFront;
  Show;
end;





posted @ 2013-11-17 13:46  XE2011  阅读(601)  评论(0编辑  收藏  举报