While working with Silverlight Line of Business applications, there may be a scenario where the user wants to open .exe applications e.g. Notepad or Calculator from the local machine. The question here is how to make this possible in Silverlight?
In Silverlight 4.0, using the AutomationFactory class we can create an instance of these .exe applications and can use them along with our Silverlight application. CreateObject is the method provided for such type of application development. To make use of this method, you need to add a reference of the .CSharp library in your Silverlight application. This library file is available in the following path on my machine:
C:\Program Files (x86)\Microsoft SDKs\Silverlight\v4.0\Libraries\Client\Microsoft.CSharp.dll
Step 1: Open VS 2010 and create a new Silverlight application targeted to use Silverlight 4.0. Name the application as ‘SL4_Running_System_Executables’.
Step 2: Right click on the project and select properties. Check the ‘Enable running application out of browser’ checkbox as shown below:
Step 3: Also click on the ‘Out-of-Browser Settings’ button and check the ‘Require elevated trust when running outside the browser’ checkbox as shown below. This will allow the Silverlight application running out of the browser to interact with the system libraries and applications.
Step 4: In the MainPage.Xaml, add two buttons as shown below:
Step 5: Use the following namespace in the MainPage.xaml.cs file
Step 6: Write the following code in the Click events for both the Buttons:
The above code makes use of the WScript object which provides access to the root object for the Windows Script Host object model. The WScript.shell provides an object of native Windows shell. You can use this object to make call to .exe’s and libraries from the local system.
Step 7: Run the application and test it by clicking on the buttons as shown below:
The business requirements here is that the end-user may want to make note of some data before passing it to the Silverlight application. In such cases, Notepad can be a lightweight program.
Similarly in some cases, the user may want to perform calculations like percentage before entering into a system. In such cases, the Calculator can be an ideal application.
Will you give this article a +1 ? Thanks in advance