Home > database >  How to execute multiple programs in the same time with a .bat file
How to execute multiple programs in the same time with a .bat file

Time:08-10

I made 2 bat files to start apps with examples below: My expectation is to execute them simultaneously, meaning after double click bat file, then 3 programs will pop up.

With the 1st example, the behavior is to execute outlook first, then both Mircrosoft Edge and OneNote still not pop up, until I stop Outlook.

Example 1

@echo off
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Outlook.lnk"
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk"
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\OneNote.lnk"
exit

With the 2nd example, both Mrcrosoft Edge and OneNote were executed simultaneously, however Outlook not until I stop OneNote.

Example 2

 @echo off
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Microsoft Edge.lnk"
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\OneNote.lnk"
"C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Outlook.lnk"
exit

My questions is why it behaves like this way and how to make these 3 programs start up in the same time ?

Shown below is the Windows config: Edition Windows 10 Enterprise Version 21H2 Installed on ‎10/‎27/‎2021 OS build 19044.1826 Experience Windows Feature Experience Pack 120.2212.4180.0

CodePudding user response:

Just add start /b before each line on your paths. The start command allows the command to be executed in another process, while /b prevents the opening of a new window.

CodePudding user response:

1)Run the first program using the start command.

2)Check the task list in a loop to see if the program has appeared there.

3)Impose some time limitation to the said loop.

4)Run the next program in case of success, exit with notification otherwise.

@ECHO 
OFF START program1.exe
FOR /L %%i IN (1,1,100) DO (
(TASKLIST | FIND /I "program.exe") && GOTO :startnext
:: you might add here some delaying
)
ECHO Timeout waiting for program1.exe to start
GOTO :EOF
:startnext
program2.exe
:: or START
program2.exe

Remember that the timing is not precise, especially if you are going to insert delays between the task list checks.

  • Related