.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Win Surprise Gifts!!!

Top 5 Contributors of the Month
Melody Anderson

Home >> Articles >> Windows Application >> Post New Resource Bookmark and Share   

 Subscribe to Articles

Registry Details of Your System Using WMI Class

Posted By:Sanjeeb Lenka       Posted Date: November 29, 2013    Points: 200    Category: Windows Application    URL: http://www.dotnetspark.com  

This article describes how to get the Registry details of your system using a WMI Class. Here I will get the information from the Win32_Registry class.


This article describes how to get the Registry details of your system using a WMI Class. Here I will get the information from the Win32_Registry class.

Win32_Registry is

The Win32_Registry WMI class represents the system registry on a computer system running Windows.

Create a new Windows Forms Application Project.

Add one button control to the form.

Design your screen as in the following screen:

Next add a reference for "System.Management".

To add the reference use the following procedure.

Go to Solution Explorer, select the project and right-click on that and choose "Add Reference" from the menu.

A window will open; in that choose the ".Net" tab.

It will show a list. In that list, choose "System.Management" and click the "OK" Button.

Now go to the code view.

Add the namespace "using System.Management;".

Write the following code in the Button Click event

private void button1_Click(object sender, EventArgs e)
            SelectQuery Sq = new SelectQuery("Win32_Registry");
            ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(Sq);
            ManagementObjectCollection osDetailsCollection = objOSDetails.Get();
            StringBuilder sb = new StringBuilder();
            foreach (ManagementObject mo in osDetailsCollection)
                sb.AppendLine(string.Format("Class : {0}", mo["__class"].ToString()));
                sb.AppendLine(string.Format("Caption : {0}", mo["Caption"].ToString()));
                sb.AppendLine(string.Format("CurrentSize: {0}", mo["CurrentSize"].ToString()));
                sb.AppendLine(string.Format("Description: {0}", mo["Description"].ToString()));
                DateTime dt = ManagementDateTimeConverter.ToDateTime(mo["InstallDate"].ToString());
                sb.AppendLine(string.Format("InstallDate: {0}", dt));
                sb.AppendLine(string.Format("MaximumSize: {0}", mo["MaximumSize"].ToString()));
                sb.AppendLine(string.Format("Name : {0}", mo["Name"].ToString()));
                sb.AppendLine(string.Format("ProposedSize: {0}", mo["ProposedSize"].ToString()));
                sb.AppendLine(string.Format("Status : {0}", mo["Status"].ToString()));

In the code above I am getting the information from Win32_Registry and showing it in a Message Box on a button click.


It represents a WMI Query Language (WQL) SELECT data query.


It retrieves a collection of management objects based on a specified query. 

This class is one of the more commonly used entry points to retrieve management information.


It represents various collections of management objects retrieved using WMI.

Now build your application. Click on the button. It will show the
Registry details in a Message box.

 Subscribe to Articles


Further Readings:


No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More Articles on C#, ASP.Net, Vb.Net, SQL Server and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend