Get the Desktop Details of Your Windows Operating System in ASP.Net


This article explains how to get the Desktop details of a user in your system. Here I will get the information from the Win32_Desktop class.

What Win32_Desktop  is

The Win32_Desktop WMI class represents the common characteristics of a user's Desktop.

Create a new ASP.Net Empty website.

Add one page in that website.

In that page drag and drop a GridView control.

Design your screen as in the following screen:


Or you can copy the following source code:

  1. <body>  
  2.     <form id="form1" runat="server">  
  3.     <div>  
  4.         <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" >  
  5.             <AlternatingRowStyle BackColor="White" />  
  6.             <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />  
  7.             <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />  
  8.             <RowStyle BackColor="#EFF3FB" />  
  9.         </asp:GridView>  
  10.     </div>  
  11.     </form>  
  12. </body>   

Next add a reference of "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 code view and write the following code:

  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Management;  
  8. using System.Data;  
  9. public partial class Default2 : System.Web.UI.Page  
  10. {  
  11.     protected void Page_Load(object sender, EventArgs e)  
  12.     {  
  13.         DataTable dt = new DataTable();  
  14.         dt.Columns.Add(new DataColumn("Name"typeof(string)));  
  15.         dt.Columns.Add(new DataColumn("BorderWidth"typeof(string)));  
  16.         dt.Columns.Add(new DataColumn("CursorBlinkRate"typeof(string)));  
  17.         dt.Columns.Add(new DataColumn("DragFullWindows"typeof(string)));  
  18.         dt.Columns.Add(new DataColumn("IconTitleFaceName"typeof(string)));  
  19.         dt.Columns.Add(new DataColumn("IconTitleSize"typeof(string)));  
  20.         dt.Columns.Add(new DataColumn("IconTitleWrap"typeof(string)));  
  21.         dt.Columns.Add(new DataColumn("Pattern"typeof(string)));  
  22.         dt.Columns.Add(new DataColumn("ScreenSaverActive"typeof(string)));  
  23.         dt.Columns.Add(new DataColumn("WallpaperStretched"typeof(string)));  
  24.         SelectQuery Sq = new SelectQuery("Win32_Desktop");  
  25.         ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(Sq);  
  26.         ManagementObjectCollection osDetailsCollection = objOSDetails.Get();  
  27.         foreach (ManagementObject MO in osDetailsCollection)  
  28.         {  
  29.             DataRow dr = dt.NewRow();  
  30.             dr["Name"] = MO["Name"].ToString();  
  31.             dr["BorderWidth"] = MO["BorderWidth"].ToString();  
  32.             dr["CursorBlinkRate"] = MO["CursorBlinkRate"];  
  33.             dr["DragFullWindows"] = MO["DragFullWindows"];  
  34.             dr["IconTitleFaceName"] = MO["IconTitleFaceName"];  
  35.             dr["IconTitleSize"] = MO["IconTitleSize"];  
  36.             dr["IconTitleWrap"] = MO["IconTitleWrap"];  
  37.             dr["Pattern"] = MO["Pattern"];  
  38.             dr["ScreenSaverActive"] = MO["ScreenSaverActive"];  
  39.             dr["WallpaperStretched"] = MO["WallpaperStretched"];  
  40.             dt.Rows.Add(dr);  
  41.         }  
  42.         GridView1.DataSource = dt;  
  43.         GridView1.DataBind();  
  44.     }  
  45. } 

In the code above I get the information from Win32_Desktop and store it in a datatable and bind it to the grid.


It represents a WQL (WMI Query Language) 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 retrieving management information.


It represents various collections of management objects retrieved using WMI.

Now build your application, it will show all details in the Grid.