Click here to Skip to main content
15,881,640 members
Articles / General Programming / File
Tip/Trick

How to launch external application or file from Silverlight 4

Rate me:
Please Sign up or sign in to vote.
3.00/5 (2 votes)
7 Sep 2010CPOL 26.1K   2   1
Launching external application or file from Silverlight 4 (out-of-browser) using Automation Factory

Problem



I have been recently trying to automate the instalation of COM server for my Silverlight app and I found it pretty hard to find any solution. The thing is I wanted to run the downloaded setup file from Silverlight code, which turned out to be not so easy in Silverlight application.


Solution


Reading KunalChowdhury's article (File Explorer using Silverlight 4 COM Interoperability), I have noticed he pointed out it is possible using COM.
After quite annnoying search I have finally found SpoonStomper's post on Silverlight forum.
Original solution was for JavaScript using ActiveX but, as I have checked immediately, it works also with AutomationFactory in Silverlight 4.


C#
private void Run(string path)
{
    try
    {
        dynamic shell= AutomationFactory.CreateObject("WScript.shell");
        shell.run(path);
     }
     catch (System.Exception)
     {
         MessageBox.Show("failure");
     }
}

The Run method creates shell object and runs application or file with path given in param. It allows to launch any external application or open any file with program related to this file.

WScript reference can be found here.

This solution will work only in out-of-browser mode with elevated permisions.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer (Junior) freelancer
Poland Poland
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralMy vote of 1 Pin
mtss9221-May-14 1:26
mtss9221-May-14 1:26 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.