如何实现通过Checkbox选项依次运行各应用程序。判断CheckBox是否选择,然后运行并等待外部程序结束,(外部程序可自动结束),然后执行下一个Checkbox是否选择。现在等待执行是CreateProcess来实现的。现在出现的情况是选中的Checkbox同时运行了。如何让他们排队运行呢?

解决方案 »

  1.   

    试试这个现成的函数:
    function WinExecAndWait32(FileName: string; Visibility: Boolean): integer;
    var
      zAppName: array[0..512] of char;
      StartupInfo: TStartupInfo;
      ProcessInfo: TProcessInformation;
      exitCode: Dword;
      aVisibility: integer;
    begin
      StrPCopy(zAppName, FileName);
      FillChar(StartupInfo, Sizeof(StartupInfo), #0);
      StartupInfo.cb := Sizeof(StartupInfo);
      StartupInfo.dwFlags := STARTF_USESHOWWINDOW;
      if Visibility then
        aVisibility := 1
      else
        aVisibility := 0;
      StartupInfo.wShowWindow := aVisibility;
      if not CreateProcess(nil, zAppName, nil, nil, false, CREATE_NEW_CONSOLE or NORMAL_PRIORITY_CLASS, nil, nil, StartupInfo, ProcessInfo) then
        Result := -1
      else
      begin
        WaitforSingleObject(ProcessInfo.hProcess, INFINITE);
        GetExitCodeProcess(ProcessInfo.hProcess, exitCode);
        result := Exitcode;
      end;
    end;
      

  2.   

    等待程序运行是已经解决的。现在是执行时,多个选项会同时执行,导致应用程序未响应。之前是一个一个的if的,后来改成下面这样还是不行。虽然这样就必须依次要选中。测试不通过。procedure TForm1.InstallClick(Sender: TObject);
    var
      InstanceID: THandle;
      Success: Boolean;begin
      installdrv1.enabled:=false;
      installdrv2.enabled:=false;
      installdrv3.enabled:=false;
      installdrv4.enabled:=false;
      installdrv5.enabled:=false;
      installdrv6.enabled:=false;
      exit.enabled:=false;
      install.enabled:=false;
      
      if drv1.Checked=true then
      begin  Success := False;
      try
      Num:=Num+1;
      State1.Lines.Add('');
      State1.Lines.Add('Chipset Driver Checked.');
      State1.Lines.Add('Chipset Driver Installing...');
      State1.Lines.Add('Please wait...');
          InstanceID := RunAndWait( PChar(ExtractFileDir(paramstr(0))+'\i1300\inf\8.6.0.1008\Intel Chipset Driver Installation UtilityPV8.6.0.1008\infinst_autol.exe -s'),1,PChar(ExtractFileDir(paramstr(0))+'\i1300\inf\8.6.0.1008\Intel Chipset Driver Installation UtilityPV8.6.0.1008\'));
          Success := InstanceID >= 32; 
      finally    if not Success then
          begin
          State1.Lines.Add('');
          State1.Lines.Add('ERROR: Chipset Driver Not Found!');
          end
      end;
          State1.Lines.Add('');
          State1.Lines.Add('Chipset Driver Installed.');
      if ((drv2.Checked=true) AND (Success=True)) OR (drv1.Checked=false) then
      begin
      Success := False;
      try  Num:=Num+1;
      State1.Lines.Add('');
      State1.Lines.Add('VGA Driver Checked.');
      State1.Lines.Add('VGA Driver Installing...');
      State1.Lines.Add('Please wait...');
      if GetSystemStr='Windows 32' then    
          begin
          InstanceID := RunAndWait( PChar(ExtractFileDir(paramstr(0))+'\i1300\VGA\Windows_OLD\WMD20070622.WHQL.Win32\ServerEngines G200e SETUP.exe'),1,PChar(ExtractFileDir(paramstr(0))+'\i1300\VGA\Windows_OLD\WMD20070622.WHQL.Win32\'));
          Success := InstanceID >= 32; 
          end
      else if (GetSystemStr='Windows Xp') OR (GetSystemStr='Windows 2003') then //XP&2003      if GetSystemXbit='x64' then
            begin
            InstanceID := RunAndWait( PChar(ExtractFileDir(paramstr(0))+'\i1300\VGA\WMD20080229.1966.P2.Win64-2003\ServerEngines G200e SETUP.exe'),1,PChar(ExtractFileDir(paramstr(0))+'\i1300\VGA\WMD20080229.1966.P2.Win64-2003\'));
            Success := InstanceID >= 32; 
            end
          else
            begin
            InstanceID := RunAndWait( PChar(ExtractFileDir(paramstr(0))+'\i1300\VGA\WMD20080229.1966.P2.Win32-2003\ServerEngines G200e SETUP.exe'),1,PChar(ExtractFileDir(paramstr(0))+'\i1300\VGA\WMD20080229.1966.P2.Win32-2003\'));
            Success := InstanceID >= 32; 
            end
               else if (GetSystemStr='Windows Vista') OR (GetSystemStr='Windows Server 2008') OR (GetSystemStr='Windows 7') OR (GetSystemStr='Windows Server 2008 R2') then
        
          if GetSystemXbit='x64' then
            begin
            InstanceID := RunAndWait( PChar(ExtractFileDir(paramstr(0))+'\i1300\VGA\WMD20080229.1966.P2.Win64-2008\ServerEngines G200e SETUP.exe'),1,PChar(ExtractFileDir(paramstr(0))+'\i1300\VGA\WMD20080229.1966.P2.Win64-2008\'));
            Success := InstanceID >= 32; 
            end
          else
            begin
            InstanceID := RunAndWait( PChar(ExtractFileDir(paramstr(0))+'\i1300\VGA\WMD20080229.1966.P2.Win32-2008\ServerEngines G200e SETUP.exe'),1,PChar(ExtractFileDir(paramstr(0))+'\i1300\VGA\WMD20080229.1966.P2.Win32-2008\'));
            Success := InstanceID >= 32; 
            end  else
        begin
        State1.Lines.Add('');
        State1.Lines.Add('The operating system does not support!');
        State1.Lines.Add('Please Try manually install!');
        Success:= False;
        end;
           finally    
          if not Success then
          begin
          State1.Lines.Add('');
          State1.Lines.Add('ERROR: VGA Driver Not Found!');
          end
        end;                                    
          State1.Lines.Add('');
          State1.Lines.Add('VGA Driver Installed.');  
        if ((drv3.Checked=true) AND (Success=True)) OR ((drv1.Checked=false) AND (drv2.Checked=false)) then
        begin  Success := False;
      try  Num:=Num+1;
      State1.Lines.Add('');                        
      State1.Lines.Add('LAN Driver Checked.');
      State1.Lines.Add('LAN Driver Installing...');
      State1.Lines.Add('Please wait...');
      if GetSystemStr='Windows 32' then    //<Windows other
          begin
            InstanceID := RunAndWait( PChar('msiexec /i '+ExtractFileDir(paramstr(0))+'\i1300\LAN\Dragon_Lake_5_OEM_Gen_158906\APPS\PROSETDX\Win32\PROSETDX.msi /passive /quiet'),1,Pchar(ExtractFileDir(paramstr(0))+'\i1300\LAN\Dragon_Lake_5_OEM_Gen_158906\APPS\PROSETDX\Win32\'));
          Success := InstanceID >= 32;
          end
      else if (GetSystemStr='Windows Xp') OR (GetSystemStr='Windows 2003') then //XP&2003      if GetSystemXbit='x64' then
            begin
            InstanceID := RunAndWait( PChar('msiexec /i '+ExtractFileDir(paramstr(0))+'\i1300\LAN\Dragon_Lake_5_OEM_Gen_158906\APPS\PROSETDX\Winx64\PROSETDX.msi /passive /quiet'),1,Pchar(ExtractFileDir(paramstr(0))+'\i1300\LAN\Dragon_Lake_5_OEM_Gen_158906\APPS\PROSETDX\Winx64\'));
            Success := InstanceID >= 32; 
            end
          else
            begin
            InstanceID := RunAndWait( PChar('msiexec /i '+ExtractFileDir(paramstr(0))+'\i1300\LAN\Dragon_Lake_5_OEM_Gen_158906\APPS\PROSETDX\Win32\PROSETDX.msi /passive /quiet'),1,Pchar(ExtractFileDir(paramstr(0))+'\i1300\LAN\Dragon_Lake_5_OEM_Gen_158906\APPS\PROSETDX\Win32\'));
            Success := InstanceID >= 32; 
            end
               else if (GetSystemStr='Windows Vista') OR (GetSystemStr='Windows Server 2008') OR (GetSystemStr='Windows 7') OR (GetSystemStr='Windows Server 2008 R2') then      if GetSystemXbit='x64' then
            begin
            InstanceID := RunAndWait( PChar('msiexec /i '+ExtractFileDir(paramstr(0))+'\i1300\LAN\Dragon_Lake_5_OEM_Gen_158906\APPS\PROSETDX\Vistax64\PROSETDX.msi /passive /quiet'),1,Pchar(ExtractFileDir(paramstr(0))+'\i1300\LAN\Dragon_Lake_5_OEM_Gen_158906\APPS\PROSETDX\Vistax64\'));
            Success := InstanceID >= 32; 
            end
          else
            begin
            InstanceID := RunAndWait( PChar('msiexec /i '+ExtractFileDir(paramstr(0))+'\i1300\LAN\Dragon_Lake_5_OEM_Gen_158906\APPS\PROSETDX\Vista32\PROSETDX.msi /passive /quiet'),1,Pchar(ExtractFileDir(paramstr(0))+'\i1300\LAN\Dragon_Lake_5_OEM_Gen_158906\APPS\PROSETDX\Vista32\'));
            Success := InstanceID >= 32; 
            end  else
        begin
        State1.Lines.Add('');
        State1.Lines.Add('The operating system does not support!');
        State1.Lines.Add('Please Try manually install!');
        Success:= False;
        end;
           finally    
        if not Success then
          begin
          State1.Lines.Add('');
          State1.Lines.Add('ERROR: LAN Driver Not Found!');
          end
        end;                                    
          State1.Lines.Add('');
          State1.Lines.Add('LAN Driver Installed.');   
        if ((drv5.Checked=true) AND (Success=True)) OR ((drv1.checked=false) AND (drv2.Checked=false) AND (drv3.Checked=false)) then
        begin  Success := False;
      try  Num:=Num+1;
      State1.Lines.Add('');
      State1.Lines.Add('SATA RAID utility Checked.');
      State1.Lines.Add('SATA RAID utility Installing...');
      State1.Lines.Add('Please wait...');        InstanceID := RunAndWait( PChar(ExtractFileDir(paramstr(0))+'\i1300\RAID\IMSM_7.8.0.1012\iata_cd.exe -s'),1,PChar(ExtractFileDir(paramstr(0))+'\i1300\RAID\IMSM_7.8.0.1012\'));
            Success := InstanceID >= 32; 
           finally    if not Success then
          begin
          State1.Lines.Add('');
          State1.Lines.Add('ERROR: SATA RAID utility Not Found!');
          end
        end;                                    
          State1.Lines.Add('');
          State1.Lines.Add(' SATA RAID utility Installed.');
        if (drv6.Checked=true) AND (Success=True) OR ((drv1.Checked=false) AND (drv2.Checked=false) AND (drv3.Checked=false) AND (drv5.Checked=false)) then
        begin  Success := False;
      try  Num:=Num+1;
      State1.Lines.Add('');
      State1.Lines.Add('TPM Checked.');
      State1.Lines.Add('TPM Installing...');
      State1.Lines.Add('Please wait...');        InstanceID := RunAndWait( PChar(ExtractFileDir(paramstr(0))+'\IFX_TPM_Professional_Package_SW_3[1].0_SP1\setup.exe /s /v/qn'),1,PChar(ExtractFileDir(paramstr(0))+'\IFX_TPM_Professional_Package_SW_3[1].0_SP1\'));
            Success := InstanceID >= 32;
           finally
        if not Success then
          begin
          State1.Lines.Add('');
          State1.Lines.Add('ERROR: TPM Not Found!');
          end
        end;                                    
          State1.Lines.Add('');
          State1.Lines.Add(' TPM Installed.');  installdrv1.enabled:=true;
      installdrv2.enabled:=true;
      installdrv3.enabled:=true;
      installdrv4.enabled:=true;
      installdrv5.enabled:=true;
      installdrv6.enabled:=true;
      exit.enabled:=true;
      install.enabled:=true;
          State1.Lines.Add('');
          State1.Lines.Add(' All Chooses Installed.'); 
        end;//end6 
        end;//end5
        end;//end3
        end;   //end2
      end;  //end