Tuesday, 26 September 2017

Batch file - wait or quit if a process running


I have 2 small batch files that change the target location of a junction point (mkref /d), in order to switch between 2 iTunes libraries.


It works well, but I would like it to stop if iTunes is already running - as iTunes will overwrite the library in the wrong target folder if I change the junction while it is running.


Is there a way to quit or pause the batch file if iTunes.exe is running?



Answer



Try adding the following to the beginning of your batch files:


tasklist /fi "Imagename eq itunes.exe" 2>NUL | find /i /n "itunes.exe">NUL
if "%ERRORLEVEL%"=="0" exit

For more information, see the documentation on the tasklist and find commands.


No comments:

Post a Comment

Where does Skype save my contact's avatars in Linux?

I'm using Skype on Linux. Where can I find images cached by skype of my contact's avatars? Answer I wanted to get those Skype avat...