Back in the day before broadband internet access, it was quite common to distribute Flash applications on CD or DVD along with large video files and interactive content. This was the only practical way for users to view video because internet connection speeds were too slow for streaming video.
But even today, there is still a demand for Interactive content on CD – a couple of examples that come to mind are educational software and media distributed at conferences and trade shows. Silverlight is an attractive option for interactive media, because of its quick adoption rate and small runtime install. So what if we wanted to use Silverlight as a solution for an Interactive CD?
There are a few ways we could go about this, including using a Stand-Alone Silverlight solution such as Desklighter. Or, we could use an HTML Application (HTA) – which is the approach I took for a recent project. An HTA is really just an HTML file, renamed to have an .HTA extension, and with optional embedded tags to control things such as Window Title, Menus, and Icon. Oh, and an HTA is a trusted application, so it can get access to the client operating system unlike a normal HTML page in a browser.
[DOWNLOAD SAMPLE CODE]
THE INGREDIENTS
1. A Silverlight Application, compiled to a XAP.
2. An HTML test page pointing to the Silverlight XAP (the testpage HTML file generated by Silverlight Tools for Visual Studio will work fine). Rename this file’s extension to .HTA so that it can be launched as an HTML Application (after renaming the file you can test launch it by double-clicking the HTA file). You can also add optional HTA attributes inside the section of your HTML to control things such as Window appearance and menus. An example Application tag is shown below, and you can find all of the HTA attributes here.
BORDER="Thin"
CAPTION="yes"
APPLICATIONNAME="Hello Silverlight DVD"
MAXIMIZEBUTTON="yes"
MINIMIZEBUTTON="yes"
SINGLEINSTANCE="yes"
SHOWINTASKBAR="yes"
SYSMENU="yes"
SCROLL="no"
SELECTION="no"
WINDOWSTATE="normal"/>
3. An autorun.inf file. This will allow us to “AutoPlay” the Silverlight application on CD or DVD. Autorun.inf is a simple text file with an [autorun] section containing the name of an Executable file to launch and an optional icon file to show:
[autorun]
OPEN=ShellExecuteWin.exe
ICON=setup.ico
* The important thing to note here is that the Autorun OPEN setting MUST point to an EXE file. We cannot point directly to our HTA file for launching.
4. A small executable file to launch the HTA application (see note above). Since we want to keep our runtime requirements to a minimum, a wise choice for this little “bootstrap” EXE is Visual C++. We can use Visual Studio 2008 to create a Win32 Project and add a call to ShellExecute, which allows us to launch another application:
ShellExecute(NULL,_T("open"),_T("AutoRunTestPage.hta"),_T(""),_T(""), 0 );
NOTE that the sample download includes the Visual C++ Project to save you some grief. But if you need to create your own VC++ launcher, remember these notes:
a. You need to add includes to windows.h and shellapi.h
b. In order to avoid dependencies on runtime DLLs which may not be present on a client’s system, you want to statically link. To do this, select Project Properties and select C/C++ and then Code Generation and make sure to select Runtime Library= Multithreaded (/MT)
THE SAMPLE DOWNLOAD
The download ZIP contains a sample implementation of a Silverlight HTA application with Autorun for CD/DVD. If you look in the DistributionFiles directory, you will see these files:
1. AutoRunSilverlight.xap is our Silverlight Application
2. AutoRunTestPage.hta is our HTML Application, containing the Silverlight App Reference
3. Autorun.inf is our Autorun configuration file
4. ShellExecuteWin.exe is our EXE launcher, created in C++ and using ShellExecute to launch the HTA
To complete the CD, you just need to burn these files onto the root folder of a disk. When a user inserts the disk, their experience will vary depending on their Autoplay settings in Control Panel.