Page view counter

Silverlight Tips of the Day - Blog by Mike Snow

Game Programming with Silverlight

Tip of the Day #111 – How to Configure your Silverlight App to run in Elevated Trust Mode

With Silverlight you can run your Out-of-Browser applications in elevated trust mode. This will allow you to relax the normal sandboxed barrier Silverlight restricts applications to. While you still will not have full control of the local machine, the following features are made available to you in elevated trust mode:

  1. Clipboard Access – Retrieve items from the system clipboard without the prompt for permissions to access  the clipboard as seen below:

    image 
  2. HTML Hosting – Display HTML Content in the WebBrowser control.

  3. Removal of Cross Domain Restrictions – Your application can interact with any domain bypassing the normal security check that required the ClientAccessPolicy.xml or CrossDomain.xml files.

  4. File Access – Your application can now directly access files without user initiated interaction that then invokes the OpenFileDialog or SaveFileDialog dialogs. However, you are still limited to user folders such as My Documents, My Videos, My Music, My Pictures and any sub folder. Example code you can execute:

    if
    (App.Current.IsRunningOutOfBrowser && Application.Current.HasElevatedPermissions)
    {
        string picturesPath = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
        string path = picturesPath + @"\test.txt";
        StreamReader sr = new StreamReader(path);

        string line = sr.ReadLine();
        while (line != null)
        {
            line = sr.ReadLine();
        }
        sr.Close();
    }

  5. Notification Window – Also know as a “toast” window, this is a small window that pops up in the lower right corner for a specified interval of time before disappearing.

  6. COM Interoperability – Direct access to COM enabled applications installed on the clients machine.

In order to configure your application to run in elevated mode open your project in Visual Studio 2010. Once open, right click on your Silverlight application in the solution explorer and select Properties. Under the Silverlight tab, check “Enable running application out of the browser” and click the “Out-of-Browser settings" button as circled below in the screenshot.

image

Once this dialog is open check the “Require elevated trust when running outside the browser” checkbox as seen circle in the screenshot below.

image

Now, when a user chooses to install your Silverlight application out of browser they will get this rather intimidating security warning dialog before they can proceed. Note that you can replace this dialog with something more friendly if your XAP is digitally signed (this will be covered in the next tip of the day).

image 

Final Notes

On a final note, you will want to make certain your application verifies it’s running in out of browser mode before making calls that are required to be in this mode before being executed. Your application can check to see if it’s running in Out-of-Browser mode through this call:

if (App.Current.IsRunningOutOfBrowser)
{
}

Also, your application can verify it has elevated permissions with this call:

if (Application.Current.HasElevatedPermissions)
{
}

Thank you,
--Mike

Comments

Microsoft Weblogs said:

With Silverlight you can run your Out-of-Browser applications in elevated trust mode. This will allow

# April 20, 2010 6:44 PM

rkrummenacher said:

Hy Mike

What about the Port-Restrictions for TCP-Sockets? Are they gone as well for Out-of-the-Browser-Applications with Elevated Trust Mode?

Thanks,

Roland

# April 21, 2010 2:08 AM

mike.snow said:

I haven't read anywhere that the restriction for sockets is gone. You could try it out though? Let me know what you find out. Thanks.

# April 21, 2010 11:35 AM

vitor_canova said:

Hi Mike,

Sorry but I think you made a mistake about clipboard access. Clipboard Access (System.Windows.Clipboard) is possible even in a browser hosted (not OOB) application.

www.silverlight.net/.../accessing-global-clipboard

Canova

# April 21, 2010 11:43 AM

mike.snow said:

Actually yes but you get a dialog asking for permissions to access the clipboard that you do not get when in elevated mode.

I guess I should clarify that that's the difference.

# April 21, 2010 11:50 AM

snelldl said:

If you're running your app as elevated, maybe you should do this check too:

if (Application.Current.HasElevatedPermissions)

{

  ...

}

# April 21, 2010 11:53 AM

mike.snow said:

Good point,added to final notes section. Thanks.

# April 21, 2010 11:59 AM

Twitter Trackbacks for Tip of the Day #111 ??? How to Configure your Silverlight App to run in Elevated Trust Mode - Silverlight Tips of the Day - Blog by Mike Snow [silverlight.net] on Topsy.com said:

Pingback from  Twitter Trackbacks for                 Tip of the Day #111 ??? How to Configure your Silverlight App to run in Elevated Trust Mode - Silverlight Tips of the Day - Blog by Mike Snow         [silverlight.net]        on Topsy.com

# April 21, 2010 12:40 PM

Silverlight Tips of the Day » said:

Pingback from  Silverlight Tips of the Day »

# April 21, 2010 6:04 PM

Silverlight Tips of the Day » said:

Pingback from  Silverlight Tips of the Day »

# April 21, 2010 6:06 PM

Silverlight Tips of the Day » This is a test said:

Pingback from  Silverlight Tips of the Day »   This is a test

# April 21, 2010 6:06 PM

Silverlight Tips of the Day » Silverlight Tip of the Day #4 – Enabling Out of Browser Applications said:

Pingback from  Silverlight Tips of the Day »   Silverlight Tip of the Day #4 – Enabling Out of Browser Applications

# April 26, 2010 1:18 PM

Play Halo: Reach with GamePro – GamePro.com | Snafu Blog Daily Information said:

Pingback from  Play Halo: Reach with GamePro – GamePro.com | Snafu Blog Daily Information

# April 29, 2010 11:53 PM

Play Halo: Reach with GamePro – GamePro.com | Snafu Blog Daily Information said:

Pingback from  Play Halo: Reach with GamePro – GamePro.com | Snafu Blog Daily Information

# April 29, 2010 11:53 PM

Carlton County Court now offers web and phone payment for fines – Pine Journal | project Blog said:

Pingback from  Carlton County Court now offers web and phone payment for fines – Pine Journal | project Blog

# May 1, 2010 1:42 AM

iPhone-More-Fun Releases iZen 1.2 for iPhone and iPod touch – iPhone World (blog) | itouch Blog said:

Pingback from  iPhone-More-Fun Releases iZen 1.2 for iPhone and iPod touch – iPhone World (blog) | itouch Blog

# May 2, 2010 6:47 AM

Enhanced local resource access ability in Silverlight 4 « Wayne's coding space – Focus on realistic, always! said:

Pingback from  Enhanced local resource access ability in Silverlight 4 « Wayne's coding space – Focus on realistic, always!

# November 7, 2010 9:16 AM

Elevated trust in Silverlight 4 · Technology Articles said:

Pingback from  Elevated trust in Silverlight 4 · Technology Articles

# November 8, 2010 5:50 PM

webtasarim said:

Mike,

Thanks for sharing, very good informations ...

# July 2, 2011 8:36 AM

Blue Ray Plus - Latest Technology News said:

Thank you for submitting this cool story - Trackback from Blue Ray Plus - Latest Technology News

# May 3, 2012 6:12 AM