top
User Name
Pass Word:

home
archives
features
links
users
faqs
registration!
Blatherings

Restart iTunes with a Batch File
Previous | Next by elfie 11 July, 2012 - 2:01 PM

@echo off
taskkill /IM itunes.exe
echo Waiting for termination to complete...
PING 1.1.1.1 -n 1 -w 5000 >NUL
echo Starting iTunes...
start "" "C:\Program Files (x86)\iTunes\iTunes.exe"

I needed to do this because sometimes iTunes and my AppleTV will forget that they know how to talk to each other. Restarting iTunes always fixes the problem, so I wanted to make a button on my remote that would accomplish this. I made the above batch file and assigned it a keyboard shortcut, which I then taught my remote how to send. Problem solved!

Obviously this process would be useful for restarting things other than iTunes.

My use of taskkill is a soft shutdown. It sends a request to the process to close itself as if you had hit the X. If you need to force a task to shutdown, add /F at the end for "force."

The PING command is a bit of a hack to insert a 5 second pause between the previous line and the next to give iTunes enough time to shut down gracefully.

Finally, the use of a start command to launch iTunes ensures that this is launched asynchronously from the batch file's process. Without using "start" the command window that runs the batch file would actually sit open until iTunes was next closed.




7/13/2012 >> ben

a) what remote are you using?

b) can you do this to wake up a sleeping computer (for electricity bill misers... like me)

c) this would be GREAT for starting something like PlayOn too, I think, if you needed to reboot that occasionally.

d) there's no way to thread.sleep(5000)?

e) awesome work, :)


7/13/2012 >> elfie

a) Harmony 880.
b) Probably. You can send almost any keyboard command via the IR receiver.
c) I do not need to do that, but you could use this for that.
d) Not natively in the windows command prompt.
e) Thanks!


7/13/2012 >> ben

ahh, so this wouldn't work with, say, a computer in another room, on another floor?


7/14/2012 >> elfie

sure it would, if you've got an IR receiver strung to it


7/15/2012 >> ben

so you'll... send me that?


7/25/2012 >> elfie

I'll send you an IR receiver? No.

Just buy any "Windows Media Remote" that comes with a USB IR dongle and you'll be good. You probably are going to need a nice long USB extension cord though.




You must be logged in to comment.

comments

links

June 2013
SunMonTueWedThuFriSat
2627282930311
2345678
9101112131415
16171819202122
23242526272829
30123456

calendar

www.flickr.com
This is a Flickr badge showing public photos from Kheiligh. Make your own badge here.

flickr