Launching XBMC with a Windows Media Center Remote
I recently took up the task of switching my media center software from Windows 7 Media Center to the Windows version of XBMC. I found XBMC easier to get working with obscure encodings of video files (it uses mplayer instead of the normal codec engine). But, my reasons for switching are not the point of this post. The point here is that switching to XBMC from Windows Media Center has a few challenges. One such challenge is getting the Windows Media Center remote to work in a nice way. Luckily, some excellent work has been done on that front. People have already provided premade media center remote configurations for XBMC. However, the “start” button on the media center remote still had the nasty habit of launching the Windows 7 Media Center app instead of launching XBMC.
I looked around the ol’ Internet for a solution to this problem. Turns out, the behavior of that “Start” or “Green” button on the media center remote is to cause a special key combination to be pressed. This key combination is bound to launching “C:\Windows\ehome\ehshell.exe.” The quickest workaround to the problem is to change ehshell.exe to something that launches XBMC. I then saw some people had written some batch files that launched XBMC. They then used a batch-to-exe converter to make it an executable and replaced ehshell.exe. That was great, but it still had a weakness. If, for some reason, XBMC was taken out of the foreground, it wouldn’t come back. Bummer. So I fixed it!
I wrote a little application to launch XBMC. It does a few things. First, it will check if XBMC is already running. If it is, it will bring it to the foreground for you. If it isn’t running, it will launch it. It will first try using the install location in the registry to find where to launch XBMC from. If it can’t find that, it will try the default location of the XBMC.exe file (both 32-bit and 64-bit versions).
Installing it still requires replacing ehshell.exe, which admittedly, is fairly annoying, but it is better than nothing!
Download The Launcher (source code and Visual Studio project are included)
Install instructions:
We need to change permissions on the default launcher so we can copy over it:
1. Go to “C:\Windows\ehome”
2. In the “ehome” directory, right click “ehshell.exe” and choose “Properties”
3. Click on the “Security” tab and click on the “Advanced” button at the bottom.
4. Click on the “Owner” tab and click the “Edit” button.
5. Select “Administrators” and hit “OK.”
6. Click “OK” in the “Advanced Security Settings for ehshell.exe” dialog.
7. In the “ehshell.exe Properties” dialog, click on “Administrators” under “Group or user names” and click the “Edit” button.
8. Select “Administrators” (or add that group if it isn’t already there) and check the “Full Control” box in the Allow column.
9. “OK” out of all the properties and permissions dialogs.
10. While in “C:\Windows\ehome”, copy ehshell.exe and paste it somewhere safe as a backup, in case you ever need to restore.
Now, we can copy the new launcher.
11. From this folder (the one this readme file is in), copy ehshell.exe
12. Paste the modified “ehshell.exe” in the “C:\Windows\ehome” directory.
Finally, here is the (very simple) source code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 | using System; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using Microsoft.Win32; namespace XbmcLauncher { static class Program { [DllImport("user32.dll")] private static extern bool SetForegroundWindow(IntPtr hWnd); /// <summary> /// The main entry point for the application. /// </summary> static void Main() { Process[] processes = Process.GetProcessesByName("XBMC"); if (processes.Length != 0) { // If XBMC is currently running, bring it to the foreground IntPtr hWnd = processes[0].MainWindowHandle; SetForegroundWindow(hWnd); return; } else { OpenXbmc(); } } private static void OpenXbmc() { string xbmcPath = null; // Attempt to find the XBMC executable location via the registry RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Software\XBMC"); if (key != null) // If the path is in the registry use it to open XBMC { xbmcPath = key.GetValue("") as string; if (LaunchXbmcProcess(xbmcPath + @"\XBMC.exe")) return; } else // Otherwise, we'll try to use the default locations { string x86Path = @"C:\Program Files\XBMC\XBMC.exe"; string x64Path = @"C:\Program Files (x86)\XBMC\XBMC.exe"; if (LaunchXbmcProcess(x86Path)) return; else LaunchXbmcProcess(x64Path); } } private static bool LaunchXbmcProcess(string path) { if (path != null && File.Exists(path)) { Process proc = new Process(); proc.StartInfo = new ProcessStartInfo(path); proc.Start(); return true; } return false; } } } |
28 Comments to “Launching XBMC with a Windows Media Center Remote”
RSS feed for comments on this post. TrackBack URI

By Tery, February 14, 2010 @ 3:58 am
Hi,
This works fine but there is a little problem, lots of us use xbmc portable mode (arg -p), maybe you can compil one launcher for each mode ?
Thanx.
TerY.
By Jacob, February 14, 2010 @ 8:53 am
Sure. I’ve reuploaded the zip file. The zip now has a portable mode folder with an ehshell.exe set to launch XBMC with the “-p” arg. If I find out there are a lot of command line parameters people like to use, I’ll have to do something more elaborate with the launcher. But, this should work for now.
By Ronald, February 16, 2010 @ 5:00 am
maybe use something like;
cacls %systemroot%\ehome\ehshell.exe /e /g administrator:F
for the first 8 steps? (just a thought)
Big thanks for your input on the Shell!
By Jacob, February 16, 2010 @ 9:09 am
I think that could replace steps 7 through 9. The problem, and please correct me if I’m mistaken here, is that Administrators don’t have ownership of that file by default. Before we can change permissions, we need to take ownership. Is there a command prompt mechanism for doing so? I can totally see these install instructions being a big pain, so anything to reduce that would be nice.
By Ronald, February 16, 2010 @ 12:17 pm
This only works in Vista/7;
takeown /F ehshell.exe
and then change the permissions.
My guess was it could be possible with robocopy but then we still need SUBINACL
By steelman1991, February 17, 2010 @ 5:16 am
Hi
Just a quick question on this – I ahve had a terrible time getting my Harmony One (emulating an MCE Remote) to launch xbmc on a consistent basis. Can you advise whether the only changes listed in your article are required. I notice that in the rar file there is also an XbmcLauncher.exe – should this be unrared anywhere I cannot find any instructions relating to this – Sorry if this is a stupid question.
By Jacob, February 17, 2010 @ 3:15 pm
I’m also using a Harmony remote emulating an MCE remote, so that certainly shouldn’t be an issue. XbmcLauncher.exe is the exact same file as ehshell.exe, just renamed. So no, you have no reason to do anything with it. You should only need to do what is listed in the install instructions. Has the launcher worked at all for you? If you double click XbmcLauncher.exe in the directory where you unzip everything, does XBMC start? If it doesn’t, the launcher is probably having trouble locating your XBMC directory. Perhaps you didn’t run the installer and just copied over the XBMC directory to your machine?
The launcher works by checking the registry key “HKEY_CURRENT_USER\Software\XBMC\(Default)” for an XBMC directory. If it fails to do that, it will check the default 32-bit and 64-bit XBMC install directories (“C:\Program Files\XBMC” or “C:\Program Files (x86)\XBMC”). If neither of those two approaches work at finding your XBMC directory, the launcher won’t know what to do and will just exit.
By steelman1991, February 17, 2010 @ 11:39 pm
Hi Jacob
Sorry my bad – I wasn’t having issues with your launcher, but with the various options available on xbmc (jhsrennie’s .reg and launching from a shortcut key). None of the solutions worked and I was having problems finding a stable solution. I just wasn’t sure what effect if anything the XbmcLauncher.exe had.
I tried your launcher with the combination of jhsrennie’s Remote-SendKeys.reg, however without the availability of a mapped ‘info’ button in his config (can’t think why this is missing from his config – might need to ask), this was useless for xbmc. I have since moved to a simulated mce keyboard activity within the Harmony set-up and everything has worked OK.
Sorry for the confusion. Everything working as it should at the moment and thanks for your hard work in providing a solution – was starting to tear my hair out trying to get this to work.
By dotbenjamin, March 10, 2010 @ 12:35 pm
Amazing — thank you so much. Bit of a hack, but it’s at least a reasonably robust one.
Thanks again!
By PiCaRd359, March 11, 2010 @ 4:56 am
Thanks for the hack, though I seem to be having some trouble. I can launch XBMC from the XBMCLauncher.exe but the remote is not launching it. Any ideas for troubleshooting? I am running XBMC 9.11 on Win 7.
By CJ, April 25, 2010 @ 4:27 pm
Awesome, thank you!
By Mei Yang, May 11, 2010 @ 11:41 pm
Thanks for the hack. Worked beautifully for me. I am using a HP MCE remote with Windows 7.
By Dave, May 21, 2010 @ 2:17 am
Works perfectly, cheers!
By martin, May 23, 2010 @ 3:05 pm
Excellent work! does exactly what it says on the tin. fabulous!
By Pete, May 25, 2010 @ 10:32 pm
Thank You for putting the time in and making this. Works perfect!!!
By mb, June 3, 2010 @ 8:00 pm
Thanks for the launcher! I’m starting to use Boxee more and more and would like to launch Boxee instead of XBMC. I think I know how to modify the source code to launch Boxee, but I’m not sure how to re-compile and create the eshell.exe afterwards. Any help would be appreciated. Others may be interested in a BoxeeLauncher as well
By Jacob, June 3, 2010 @ 8:23 pm
Yeah, it shouldn’t be too much of a hassle to make it work for Boxee. Especially if the Boxee installer creates a registry key pointing to where the program is the same was as XBMC. I’ve been meaning to give Boxee a run for a while now, I’ll see what I can whip up.
By Ulme, June 5, 2010 @ 3:49 am
Hey,
nice work! Works great at my system (x64 win7). But, I have “ultramon” running, which allows me to start an executable on the 2nd Monitor . . . (exe link: “C:\Program Files\UltraMon\UltraMonShortcuts.exe” /l C:\ProgramData\Realtime Soft\UltraMon\ShellShortcuts\Media Center.umshortcut”)
I want to change the startcommand of the launcher. How can I do that?
By vilrockerdefer, August 7, 2010 @ 3:42 pm
Hello,
I seem to have a problem getting this to work on XP 32bit : whenever I rename, move or erase ehshell.exe, after a few seconds it reappears. If, during that time I copy your ehshell, the previous ehshell overwrites it.
Help !
By vilrockerdefer, August 7, 2010 @ 6:18 pm
Well, through safe mode and reading-only your file, I was able to place it right.
Problem is, when I push the green button I get this error : “strong name validation failed for assembly ‘c:\windows\ehome\ehshell.exe’. The file may have been tampered with or it was partially signed but not fully signed with the correct private key”
Still begging for help…
By Jacob, August 7, 2010 @ 6:42 pm
Windows XP? Do you mean Windows Media Center 2005 or XP? I’m not familiar with what eshell.exe normally launches on XP. Anyway, when files on XP are replaced, they are being copied from “%windir%\system32\dllcache.” It’s like an auto-restore mechanism in case one of them gets altered by malware or something. (I used to have this issue when trying to replace Notepad.exe with a different text editor). That said, there are a few ways to address this. You could just copy the modified eshell.exe to the system32\dllcache directory first. See this article: http://blogs.msdn.com/b/omars/archive/2004/04/30/124093.aspx – it’s meant for notepad replacement, but the same concept should apply for eshell.exe.
By vilrockerdefer, August 8, 2010 @ 6:28 am
Thanks for answering. I did the above method and that works indeed. But I still get the error message I mentioned, and a second one I didn’t mention before but that was already there too after I click the first : “EHshell.exe – common language runtime debugging services. Application has generated an exception that could not be handled. Process id=0xadc (2780), Thread id=0xae0 (2784).”
I have the option to click CANCEL to debug the application. But if I do that I have another message stating that I don’t have the resitered “jit debugger”.
Au secours !
By Vazgen Koudagooli, August 9, 2010 @ 8:58 pm
Im using a AVS MCE certified windows remote. Did the patch job copied the exe and works. I press windows button and it launches XBMC..NOW THIS IS PROBLEM.. XBMC keeps launching itself. I dont press the button and xbmc is completely shut down…every 10 sec it starts by itself..any help
By Vazgen Koudagooli, August 9, 2010 @ 9:01 pm
wait i just restarted PC and seems this problem is gone
By sufreak, August 17, 2010 @ 12:05 pm
If you have a harmony remote, make life easy. Program the Shortcut Hotkey, and map everything over to keyboard commands. Problem solved.
The only thing more you can do is use the advancedconfig file to create a Quit function.
Now, I have my system launch XBMC when I switch to my Media Center, and it quits XBMC when I “power off”.
My next step is to get the sleep functions working, and everything will be good to go.
By Mal, August 26, 2010 @ 2:12 pm
Just what I needed. Using a cheap wireless keyboard with WMC buttons – now XMBC buttons.
Thanks
By Derek, August 30, 2010 @ 8:02 pm
Hi,
One more refinement would make this already great script perfect!
If you press the green button while XBMC is already running, but is either minimized or in windowed mode, it would be really great if it would un-minimize and switch to fullscreen mode.
I have no idea if this is possible.