用WinExec执行A程序
用WaitForSingleObject等待A的结束
用WinExec执行B程序
用WaitForSingleObject等待B的结束
用WinExec执行B程序
用WaitForSingleObject等待B的结束
...

解决方案 »

  1.   

    写多次的WinExec(),应该可以吧,就不知有没有负作用?
      

  2.   

    iampawpawcsdn的思路是正确的,不过有一点错误:
    用WinExec运行程序不能得到该程序的过程句柄,必须改用ShellExecute(或ShellExecuteEx、CreateProcess、CreateProcessAsUser)运行,用得到的进程句柄作为参数调用WaitForSingleobject.
      

  3.   

    对不起,刚才说错了:ShellExecute也是不行的只能用ShellExecuteEx、CreateProcess、CreateProcessAsUser三者中的一个。
    下面是用ShellExecuteEx实现的(Uses ShellAPI):
    procedure RunAndWait(Directory,FileName,Param:String;hwndParent:HWND);
    var
      ExecInfo:TShellExecuteInfo;
    begin
      ExecInfo.cbSize := sizeof(ExecInfo);
      ExecInfo.fMask := SEE_MASK_NOCLOSEPROCESS ;
      ExecInfo.lpVerb := nil;
      ExecInfo.lpFile := PChar(FileName);
      ExecInfo.lpParameters := PChar(Param);
      ExecInfo.lpDirectory := PChar(Directory);
      ExecInfo.nShow := SW_NORMAL;
      ExecInfo.Wnd := hwndParent;
      ShellExecuteEx(@ExecInfo);
      if (ExecInfo.hProcess <> 0) then
        WaitForSingleObject(ExecInfo.hProcess,INFINITE);
    end;
    procedure TForm1.Button1Click(Sender: TObject);
    begin
      RunAndWait('','calc.exe','',Handle);
      RunAndWait('','notepad.exe','',Handle);
      RunAndWait('','mspaint.exe','',Handle);
    end;