用winexec执行多次(比如100次)操作,如何返回每次操作完成后的消息,并可以用进度条显示。(请问用线程,该如何操作?)
如果是在网络环境中,因为环境的不同,执行一次操作的时间也会不同,可能出现上一次的操作没有完成就进入了下一次操作,导致整个程序出错。
怎样解决这种问题或改进。
请各位富翁解答。谢谢!

解决方案 »

  1.   

    用system("command");它是阻塞方式的上一次的操作完成才进入了下一次操作
      

  2.   

    system("command");
    怎么用呢???
      

  3.   

    使用下面的函数
    function CreateProcessAndWait(const AppParams: String; Visibility: word;
                                  ProcessMessage: boolean = true;
                                  WaitTime: integer = 10000): DWord;
    var
       SI: TStartupInfo;
       PI: TProcessInformation;
       Proc: THandle;
       MaxWaitTime: integer;
    begin
       FillChar(SI, SizeOf(SI), 0);
       SI.cb := SizeOf(SI);
       SI.wShowWindow := Visibility;
       // Must send NULL for the first Param if DOS app
       if (not CreateProcess(nil, PChar(AppParams),
                 nil, nil,
                 FALSE, NORMAL_PRIORITY_CLASS,
                 nil, PChar(ExtractFilePath(AppParams)),
                 SI, PI) ) then
          raise Exception.CreateFmt('无法执行程序: ' + AppParams + ' 错误代码: %d', [GetLastError]);
       Proc := PI.hProcess;
       CloseHandle(PI.hThread);   MaxWaitTime := WaitTime div 50;   while (WaitForSingleObject(Proc, 50) = WAIT_TIMEOUT) and ( MaxWaitTime > 0 ) do
       begin
         if ProcessMessage then Application.ProcessMessages;
         Dec(MaxWaitTime);
       end;   GetExitCodeProcess(Proc, Result);   CloseHandle(Proc);
    end;