Execute shortcut links from a batch file and don't wait for application to exit

拜拜、爱过 提交于 2019-12-04 05:58:16

Try the first way, but take the /B off of the START command. That way, the process will launch in a new window, so it shouldn't cause it to wait.

With the /B, it's going to launch the process in the same window. So if that process blocks for some reason, then you won't get control back until it finishes. For example, consider the following batch file, foo.bat (you need sleep command for this, I have cygwin so it comes with that):

echo hi
sleep 5

From a command prompt, if you type

START /B foo.bat

you'll notice that control won't come back to the command prompt until the sleep finishes. However, if we do this:

START foo.bat

then control comes back immediately (because foo.bat starts in a new window), which is what you want.

Agent_9191

dcp's answer pointed in the right direction by trying it without the /B flag, but it wasn't the solution. Apparently START will take the first quoted string, regardless of the order of parameters passed to it, as the title of the new window rather than assuming it is the executable/command. So when the START processes launched they had the shortcut links as the title of the window, and the starting directory was the working directory of the main batch file. So I updated my file to batch file to the following and it works:

@FOR /F "usebackq delims==" %%f IN (`dir /b "S* - *.lnk"`) DO START /B /I "TITLE" "%%f"
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!