Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

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.

share|improve this answer
1  
Perfect, thanks! And with a few GOTOs and TIMEOUT, I made it wait and re-attempt every 5 seconds until iTunes.exe is closed. –  mtone May 27 '12 at 21:08
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.