Thursday 30 October 2008

Start Media Center on a Particular Channel

I was wandering the other day: how is it possible to start Windows Media Center, in fullscreen mode, on a particular channel (BBC News 24), instead of having to go through the menu system, say, in the morning when my light turns on? (except this time it'll be my computer that switches it on, not the alarm clock)

I started googling for command line Media Center (ehshell.exe) operators/switches and quickly came across this page.

This bit of script (in a batch file) will start Media Center, maximised, on the last channel that was being watched:

start /MAX %systemroot%\ehome\ehshell.exe /homepage:VideoFullscreen.xml
(all one line)

There were no parameters that could be passed to the .exe that would specify what channel was going to be displayed. The fact that Media Center remembered the last channel suggested it had to be stored somewhere. I had a look in the ehome directory to see if there was anything in any files there that changed when the channel changed, all to no avail. The next stop was the registry.

Under HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\ the key Media Center can be found, and within that, Settings, within that, VideoSettings. Now, in this key you'll find a string (REG_SZ) called _tvChannel, this string contains the last/current channel you were/are on (_tvChannelPrev contains the one before that); change it, then when Media Center starts, and you navigate to Live TV, it starts on that channel.

Channel 80, in the UK (freeview), is BBC News 24. Just change the 80 to whatever channel you want. There are two ways I've combined the above to make it easier; the first involves a batch script and a .reg file:

tvChannel.reg ...

Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Media Center\Settings\VideoSettings]
"_tvChannel"="80"


startNews.bat ...

@echo off
echo Ammending entry in registry...
regedit /s tvChannel.reg
echo Starting Media Center at channel set in .reg file...
start /MAX %systemroot%\ehome\ehshell.exe /homepage:VideoFullscreen.xml
exit


Running startNews.bat will start Media Center at the channel specified in tvChannel.reg. This, however, isn't very flexible; files need to be manually edited if a different channel is required. A python script would be better, one which outputed the channel, passed as a command line argument, to a .reg file. which was then called. Please keep in mind this is a quick script, i'm sure it could be quite heavily optimised, but it does what it needs to do. Here is is:


Sorry about the image, blogger/blogspot strips out the tabs (as well as, disgusting as they are, spaces instead of tabs). The same could be achieved with a more advanced batch script, but, to me, a python script seemed much easier. I saved this python script as channelLaunch.py so when I use it, the command is:

python channelLaunch.py 80

That's it! Hope it can be of some use to someone.

Thanks

Chris