Follow shortcuts from a batch file and do not wait for the application to exit

I have several applications that seem open to me at the same time, and instead of relying only on the startup folder to run them at the same time (and therefore I can open them all if some were closed at some point during the day) I created a shortcut folder similar to Linux launches. Therefore, in the folder I have shortcuts similar to:

  • S00 - Outlook.lnk
  • S01 - Notepad ++. lnk
  • S02 - Chrome.lnk
  • S03 - Skype.lnk

I created a batch file that will iterate over all the links that match the naming format and run them. The contents of this batch file at the moment are:

@FOR /F "usebackq delims==" %%f IN (`dir /b "S* - *.lnk"`) DO "%%f" 

It will launch most of the links that I tried, but some of them start and wait for the process to exit, thereby preventing the opening of new scripts. Is there a way to execute shortcuts without waiting for processes to exit the batch file? Or is this a lost reason, and should I look for a Powershell solution instead?

Things I've tried so far:

  • Change content to

     @FOR /F "usebackq delims==" %%f IN (`dir /b "S* - *.lnk"`) DO START /B /I "%%f" 

    It launches the command line in the background, but never launches the link target.

  • Change content to

     @FOR /F "usebackq delims==" %%f IN (`dir /b "S* - *.lnk"`) DO %comspec% /k "%%f" 

    It launches the first link, but waits.

+6
source share
2 answers

dcp answer pointed in the right direction, having tried it without the /B flag, but that was not the solution. Apparently, START will accept the first quoted string, regardless of the order of the parameters passed to it, as the title of the new window, and not consider it an executable / command. Therefore, when starting the START processes, they had link shortcuts as the window title, and the start directory was the working directory of the main batch file. So I upgraded my file to a batch file to the following and it works:

 @FOR /F "usebackq delims==" %%f IN (`dir /b "S* - *.lnk"`) DO START /B /I "TITLE" "%%f" 
+7
source

Try the first method, but release /B from the START command. Thus, the process will be launched in a new window, so it should not make it wait.

Using / B, it will start the process in the same window. Therefore, if this process is blocked for some reason, you will not gain control until it ends. For example, consider the following batch file: foo.bat (for this you need the sleep command, I have cygwin, so it is):

 echo hi sleep 5 

From the command line if you type

 START /B foo.bat 

You will notice that the control will not return to the command line until sleep is complete. However, if we do this:

 START foo.bat 

then control returns immediately (because foo.bat starts in a new window), which is what you need.

+7
source

Source: https://habr.com/ru/post/889116/


All Articles