我循环调用ShellExecute(".exe",""),
for int i:=0 to 10 do
begin
  ShellExecute(".exe","","");
End;因为我的exe文件里面会有运行Cmd的命令,所以每次ShellExecute就会有cmd的窗体弹出来,有什么办法等一个exe完全运行完毕再进行下一个ShellExecute的操作?

解决方案 »

  1.   

    for int i:=0 to 10 do
    begin
      ShellExecute(0, 'Open', PChar('c:\sendmail.exe'), PChar('-fi ' + sTempFile), nil,SW_SHOWNORMAL);
    End;sTempFile是我要用的参数。
    因为我的exe文件里面会有运行Cmd的命令,所以每次ShellExecute就会有cmd的窗体弹出来,有什么办法等一个exe完全运行完毕再进行下一个ShellExecute的操作?
      

  2.   

    参考这个程序,应用程序也适用的:
    http://community.csdn.net/Expert/FAQ/FAQ_Index.asp?id=104460
      

  3.   

    能不能生成一个批处理以后再运行?命令行下的start wait可以等待一个程序运行结束了再执行下面的程序
      

  4.   

    class function SynchroExecute(const AExecutedFileName: string;
      const AWaitTime: Integer; const AIsShow: Boolean): Boolean;
    var
      stinfo:TStartupInfo;
      psinfo:TProcessInformation;
      sap,sat:TSecurityAttributes;
    begin
      Result:=False;
      stinfo.dwFlags:=STARTF_USESHOWWINDOW;
      stinfo.cbReserved2:=0;
      stinfo.lpReserved:=nil;
      stinfo.lpReserved2:=nil;
      stinfo.lpDesktop:=nil;
      if not AIsShow then
        stinfo.wShowWindow:=SW_HIDE
      else
        stinfo.wShowWindow:=SW_SHOWNORMAL;
      stinfo.cb:=SizeOf(TStartupInfo);  sap.lpSecurityDescriptor:=nil;
      sap.bInheritHandle:=True;
      sap.nLength:=SizeOf(TSecurityAttributes);
      sat.lpSecurityDescriptor:=nil;
      sat.bInheritHandle:=False;
      sat.nLength:=SizeOf(TSecurityAttributes);  if FileExists(AExecutedFileName) and
        CreateProcess(PChar(AExecutedFileName),'',@sap,@sat,False,NORMAL_PRIORITY_CLASS,nil,PChar(ExtractFilePath(ExpandFileName(AExecutedFileName))),stinfo,psinfo) then
      begin
        CloseHandle(psinfo.hThread);
        Result:=WaitForSingleObject(psinfo.hProcess,AWaitTime) = WAIT_OBJECT_0;
        CloseHandle(psinfo.hProcess);
      end
      else begin
        RaiseLastOSError;
      end;
    end;