执行并等待进程完成

function ExecAppWait(AppName, Params: string): Boolean;  
var 
  ShellExInfo: TShellExecuteInfo;  
begin 
  FillChar(ShellExInfo, SizeOf(ShellExInfo), 0);  
  with ShellExInfo do begin 
    cbSize := SizeOf(ShellExInfo);  
    fMask := see_Mask_NoCloseProcess;  
    Wnd := Application.Handle;  
    lpFile := PChar(AppName);  
    lpParameters := PChar(Params);  
    nShow := sw_ShowNormal;  
  end;  
  Result := ShellExecuteEx(@ShellExInfo);  
  if Result then 
    while WaitForSingleObject(ShellExInfo.HProcess, 100) = WAIT_TIMEOUT do 
    begin 
      Application.ProcessMessages;  
      if Application.Terminated then Break;  
    end;  
end;

posted @ 2010-08-01 14:31  覆雨翻云  阅读(177)  评论(0)    收藏  举报