You can find a sample on www.silverlight.net or google(bing) it. The purpose of this post is not to show you how to create a Out Of Browser(OOB) application using visual studio / Silverlight but what happens behind the scene and how you can re-use a silverlight xap package to deploy it on any machine by xcopy or a media drive and run it as a desktop application out of browser style.
First of All, creating a Silverlight Out of Browser Application is one line of code and the change in deployment manifest. Please refer to http://timheuer.com/blog/archive/2009/03/18/silverlight-3-offline-update-framework.aspx to understand silverlight offline/update behavior
In order to support Out of Browser in Silverlight, you just need to call Application.Current.Install() on user action as shown below.
private void Button_Click(object sender, RoutedEventArgs e)
{
Application.Current.Install();
}
When you install the application, it downloads the content(xap package) and generate the html file to host the silverlight app along with some metadata. Everything is generated at isolated storage, as shown below in Windows XP and server 2003
<systemdrive>:\Documents and Settings\<username>\Local Settings\Application Data\Microsoft\Silverlight\OutOfBrowser\<appid>
AppId is generated at runtime which includes some random number along with domain name so for example, if you are browsing it on a localhost, AppId could be something like “2748978495.localhost”.
How does OutOfBrowser Silverlight 3 App Work?
1. Silverlight 3 runtime installs “sllauncher.exe” to launch a silverlight xap package, on my machine it is installed at <system drive>:\Program Files\Microsoft Silverlight\sllauncher.exe
2. When you install Silverlight App as OOB, it downloads the xap package at isolated storage
3. Silverlight runtime creates a “metadata” and generate “index.html” file to host the silverlight control at isolated storage
4. When you click on shortcut or start-> to launch Silverlight app, it has a command line target to launch “sllauncher.exe <appid>”, appid is nothing but the isolated storage folder name
5. sllauncher is a win32 app which loads silverlight plugin(npctrl.dll) along with IEFrame.dll to host silverlight
6. Isolated storage also includes “index.html” which hosts the silverlight xap package, “sllauncher.exe” loads IEFrame to host html/silverlight control using browser host service
Below is the snapshot of isolated storage when you install silverlight application as out of browser
What does metadata contain?
Silverlight metadata for out of browser application as shown below can be directly edited in a hex editor(unicoded string , not a binary file) or a notepad
You can open it using any text editor, no need of using hex editor.
I have quickly put together a wpf app with bunch of controls slapped in to read/modify silverlight oob metadata, click to download along with source form here to view/modify metadata
Below is the snapshot of Silveright Out of browser application modified metadata
You can pretty much modify everything in metadata.
Can I modify metadata or run out of browser silverlight xap package without downloading it?
Absolutey, Out of Browser is not really out of browser because you do need a host to host silverlight xap package so Silverlight Team did a clever implementation to load html file using SLLAUNCHER.exe and of course sllauncher uses the same infrastructure as real browser does by loading silverlight plugin(npctrl.dll-com dll) to bootstrap silverlight core clr.
Steps to create your own out of browser silverlight app to host any xap package without downloading/installing it from silverlight app on internet
1. click to download SLMetaData along with source to view/modify metadata , it also includes a zip file with metadata,xap and html which you can unzip to execute sllauncher.exe
2. launch slmetadata.exe and click on File->Open to open “metadata”
3. Modify any of the field you want and click on to save the metadata
4. Create “index.html” file and specify the xap package path as shown below
<html xmlns=”http://www.w3.org/1999/xhtml” >
<head>
<style type=’text/css’>
html, body { height: 100%; overflow: auto; }
body { padding: 0; margin: 0; }
#silverlightControlHost { height: 100%; }
</style>
</head>
<body scroll=”no” onload=”document.getElementById(‘_sl’).focus()”>
<div id=”silverlightControlHost”>
<object id=’_sl’ data=”data:application/x-silverlight,” type=”application/x-silverlight” width=”100%” height=”100%”>
<param name=”source” value=”D:/SilverlightOOB/application.xap”/>
<param name=”background” value=”White”/>
<param name=”enableGPUAcceleration” value=”False”/>
<a href=”http://go.microsoft.com/fwlink/?LinkID=124807″ style=”text-decoration: none;”>
<img src=”http://go.microsoft.com/fwlink/?LinkId=108181″ alt=”Get Microsoft Silverlight” style=”border-style: none”/>
</a>
</object>
<iframe style=’visibility:hidden;height:0;width:0;border:0px’></iframe>
</div>
</body>
</html>
5. Make sure that the path to the “index.html” file is same as specified under the LaunchPath in metadata
6. Make sure that the name of the metadata file is “metadata” and is copied at the same location as your html file
7. Execute the following command “sllauncher.exe <folder path to html file>”, make sure sllaucnher.exe is in your path
8. you can also download the complete zip package to try it out by executing the above command
for example -”sllauncher.exe D:\SilverlightOOB”
That’s all, Silverlight OOB is possible with the help of loader which gets installed along with silverlight 3 runtime which does use IEFrame so not really out of browser
but out of browser indeed
Below is the snapshot of html, folder path and command prompt

FolderPath Snapshot

Command Prompt Snapshot


Shaan says:
Very very useful. Thank you
[Reply]
cesnek says:
Metadata is not a binary file.
It is Unicode file. You can edit it with notepad.exe
[Reply]
prashant Reply:
December 15th, 2009 at 5:49 pm
@cesnek, Yup its not a binary file, there was no need to show hex editing. I do use unicode encoding in wpf app to read the strings, my bad.
Thank You for pointing it out.
[Reply]
Shemeka says:
Awesome! So what about packaging it as a dmg to install on a mac?
[Reply]
prashant Reply:
December 17th, 2009 at 7:08 am
@Shemeka, Sorry, I don’t know enough on mac os. Next year, i will start working on mac
[Reply]
alex says:
Hi,
It is very useful for windows. But I would like to know how if works in mac os x, could you provide more information?
[Reply]
roger says:
Hi,Can you give some information about how it works on mac os x? Thank you!
[Reply]
Pingback/Trackback
Primordial Ooze : del.icio.us links for Today
hoyt says:
Thanks for the great tips here. Is there a way to deploy a SL 4 app with elevated permissions without having to go through the install/download process? I can get the app up and running by editing the index and metadata, but it does not have elevated permissions. Any potential workarounds?
[Reply]
Prashant says:
Thanks for the tip, tried out the same approach on a windows server 2003 which has silverlight 4 RTM in it, and sllauncher.exe foldername does not work.
[Reply]
Digital says:
Cool post,
Although i think this could work you are giving up the chances of getting an update right?
Without ‘source’ it won’t be possible to get a new version of your SL OOB, am I right?
[Reply]
Anonymous says:
hey hoyt, try sllauncher.exe with emulate option.
[Reply]
Vera says:
I’m a MS Windows child, but now have to write Silverlight application that works on MAC too. Does this work on MAC too? Thanks!
[Reply]
prashant Reply:
December 29th, 2010 at 2:14 pm
@Vera, Yes, it does. You can watch channel 9 video http://channel9.msdn.com/Blogs/mtaulty/Silverlight-3-Running-Out-Of-Browser-Apps-on-the-Macintosh
[Reply]