System Information from Registry in Silverlight 4


Introduction

In this article we will see how we can access the registry to see the System Information in Silverlight 4.

Create Silverlight Application

Fire up Visual Studio 2010 and create a Silverlight Application and name the solution as SystemInformationSample.

1.gif 

We should enable the OutOfBrowser mode and enable the Trust level, so that we can access the registry key value.
 
2.gif

3.gif

To Access the COM InteropAutomation Factory we should use the following Namespace.

4.gif 

Now let's add the Microsoft.CSharp assembly to the project reference so that we can use dynamic programming.

5.gif 

Now let's have a Button which will display the OS version when it is clicked.

6.gif 

On the click event let's write down the following code.

7.gif 

As you see in the above code display, we are first checking whether the application is running in OutOfBrowser mode and the application should have Elevated previlage.

Then we are checking whether AutomationFactory is available. If it is available then create an object os the WScript.shell.

And finally out of that we would get the registry key value.

Now run the application and install the application on the client machine.

8.gif 

Then click on Install to install it.

9.gif 

Now click the Button and you would get the OS version in a Message Box.

10.gif
 
That's it. You can also try for the following keys to get specific OS related information.

11.gif

Hope this article helps.


Similar Articles