Building setup packages for Media Center add-ins
Windows XP Media Center Edition supports two types of add-ins - hosted HTML applications and Media Center add-ins (also known as background add-ins). I will cover hosted HTML applications separately. I will focus on creating setup packages for Media Center add-ins in this article.
I have created an example setup package for a Media Center add-in using WiX that I will describe in more detail in the rest of this article. You can find a downloadable example of the WiX source file for a Media Center add-in setup that I will use in the rest of this article at this location. I tried to create this example using what appear to be the steps that would be needed for a "typical" Media Center add-in, so hopefully this will be useful for most add-ins that you might need to create setup packages for.
Payload contained in an add-in setup package
A Media Center add-in is a managed code assembly that can call Media Center extensibility APIs to interact with and control Media Center. There are a few types of files that comprise a background add-in:
- A managed assembly
- An XML file that is used to register the add-in so that Media Center knows how to launch it
- A bitmap that is displayed in the Media Center UI that can be clicked on to launch the add-in
- Other resource files used by the add-in
Actions performed in an add-in setup package
The setup for the example Media Center add-in that I have created consists of the following activities:
- Validate that the user launching setup has administrative privileges
- Validate that the OS being installed on is Windows XP Media Center Edition, contains the correct version of Media Center and contains the file %windir%\ehome\RegisterMceApp.exe that will be needed later
- Install the files - the example installs a managed DLL, an XML file and a PNG file
- Launch %windir%\ehome\RegisterMceApp.exe as a custom action to register the add-in with Media Center
More details about the design of an add-in setup package
There are a few important design considerations that have been applied while creating this example setup package for a Media Center add-in.
1. Media Center add-in assemblies should be installed to the GAC
The Media Center SDK states that add-in assemblies must be installed in the global assembly cache (GAC) or to %windir%\ehome (the local directory where Media Center files are installed to) in order for Media Center to be able to load them. As a best practice, add-ins should be installed to the GAC as opposed to %windir%\ehome. This is accomplished in the sample add-in by adding the attribute Assembly=".net" to the File element that represents the add-in assembly:
<File Id="myaddin.dll" Name="myaddin.dll" KeyPath="yes" src="myaddin.dll" Checksum="yes" Vital="yes" Assembly=".net" />
2. The way that RegisterMceApp.exe is run is important
As I previously described in this blog post, RegisterMceApp.exe will return non-zero values (which indicate failure to Windows Installer) if an application that is already unregistered is unregistered again or if an application that is already registered is registered again. Because of this, the example setup package runs RegisterMceApp.exe /u and ignores the return code and then runs RegisterMceApp.exe in installation mode and checks the return code during initial installation and repair. During uninstall, it runs RegisterMceApp.exe /u and ignores the return code.
3. An add-in setup package should check for its prerequisites
An add-in should check and make sure that the OS it is installed on is a valid Media Center OS and that it is running the version of Media Center that the add-in is designed for. The Media Center SDK does not document any official ways of detecting Media Center OS versions, so I chose to use the registry-based method that Media Center hotfixes use for the example add-in. The following registry key/value can be used to identify Media Center version:
[HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Media Center]
Ident = REG_SZ
- Ident value 2.8 represents Media Center 2004
- Ident value 3.0 represents Media Center 2005
- Ident value 3.1 represents Media Center 2005 with Update Rollup 1
- Ident value 4.0 represents Media Center 2005 with Update Rollup 2
- Ident value 5.0 represents Media Center on Windows Vista
The example add-in package checks that the OS is in the Windows XP family by validating that VERSIONNT = 501 and also checks for Media Center 2005 with Update Rollup 2.
The example add-in setup package also validates that the file %windir%\ehome\RegisterMceApp.exe exists on the system at the beginning of setup because it is needed later in the setup process.
Finally, the add-in setup package has a launch condition that checks for administrative rights by using the Privileged property and blocks setup from running if the user running setup does not have administrative rights.
Using the example to create other add-in setup packages
You can use the following steps to create an MSI-based setup package for your Media Center add-in using my example as a template:
1. Download the latest build of version 2.0 of the WiX toolset and save it to your local hard drive
2. Download the example WiX source file for a Media Center add-in that I posted and save it to your local hard drive
3. Update the WiX source file as appropriate for your add-in:
- Provide real product name/description/version information at the top
- Provide the real names of the files you need to install
- Use a tool such as GuidGen to create GUIDs for the product code, upgrade code and any components you will be installing
- Update the prerequisite checks if necessary so that your setup will support the appropriate Media Center version for your add-in
4. Compile your add-in MSI using the following command lines and WiX tools:
- candle.exe <full path to your WXS file> -out <your WIXOBJ file>
- light.exe <your WIXOBJ file> WixUI.wixlib -loc WixUI_en-us.wxl -out <your MSI file>
Note: the files candle.exe, light.exe, WixUI.wixlib and WixUI_en-us.wxl are all included in the WiX toolset. The toolset also includes a help file (named wix.chm) that you can use as a reference if you want to create more advanced MSI packages using the above example and information as a basis.
Comments
Anonymous
February 20, 2006
After spending some time reading Media Center SDK documentation regarding setup and deployment of Media...Anonymous
August 21, 2006
Anthony Park has been working on a Windows Vista version of his MCEBrowser application.&nbsp; As part...Anonymous
August 24, 2006
Question:
I read your previous post about customizing the Windows Media Center Start menu in Windows...Anonymous
September 12, 2006
I have previously posted an article and a follow-up blog post describing how to use WiX to build MSI...Anonymous
September 21, 2006
A couple of folks on the Windows Media Center team tried out the Veronica's Radio sample that Charlie...Anonymous
April 07, 2007
Looks like the sample code for this gone now :(Anonymous
April 07, 2007
Hi Ryan - Sorry for the hassle here. It looks like my file server is down for maintenance again. The sample included in this blog post is essentially the same and the one shipped in the Media Center SDK for the Q and Z sample applications. I used the sample described in this blog post as a basis for the WiX authoring for Q and Z. In the meantime, I'd suggest that you download and install the Media Center SDK from http://www.microsoft.com/downloads/details.aspx?FamilyId=A43EA0B7-B85F-4612-AA08-3BF128C5873E&displaylang=en, and then look at the sample setup for the Q application. It is located at %ProgramFiles%Microsoft SDKsWindows Media Centerv5.0SamplesWindows Media Center Presentation Layer SamplesQSetup (if you installed the SDK to the default location). Hopefully this helps....Anonymous
April 30, 2007
I haven't been keeping up with the Media Center Sandbox forums as well as I would like to lately, andAnonymous
June 20, 2007
As part of his series about creating a Windows Vista Media Center application, Steven Harding recently