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

Introduction

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.

Design
 
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:

Desktop-Details-of-your-Windows-Operating-System-1.jpg

Or you can copy the following source code:

<body>

    <form id="form1" runat="server">

    <div>

        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" >

            <AlternatingRowStyle BackColor="White" />

            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />

            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />

            <RowStyle BackColor="#EFF3FB" />

        </asp:GridView>

    </div>

    </form>

</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.

Desktop-Details-of-your-Windows-Operating-System-2.jpg

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

Desktop-Details-of-your-Windows-Operating-System-3.jpg

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

Desktop-Details-of-your-Windows-Operating-System-4.jpg

Now go to code view and write the following code:
 

using System;

using System.Collections.Generic;

using System.Linq;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Management;

using System.Data;

public partial class Default2 : System.Web.UI.Page

{

    protected void Page_Load(object sender, EventArgs e)

    {

        DataTable dt = new DataTable();

        dt.Columns.Add(new DataColumn("Name", typeof(string)));

        dt.Columns.Add(new DataColumn("BorderWidth", typeof(string)));

        dt.Columns.Add(new DataColumn("CursorBlinkRate", typeof(string)));

        dt.Columns.Add(new DataColumn("DragFullWindows", typeof(string)));

        dt.Columns.Add(new DataColumn("IconTitleFaceName", typeof(string)));

        dt.Columns.Add(new DataColumn("IconTitleSize", typeof(string)));

        dt.Columns.Add(new DataColumn("IconTitleWrap", typeof(string)));

        dt.Columns.Add(new DataColumn("Pattern", typeof(string)));

        dt.Columns.Add(new DataColumn("ScreenSaverActive", typeof(string)));

        dt.Columns.Add(new DataColumn("WallpaperStretched", typeof(string)));

        SelectQuery Sq = new SelectQuery("Win32_Desktop");

        ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(Sq);

        ManagementObjectCollection osDetailsCollection = objOSDetails.Get();

        foreach (ManagementObject MO in osDetailsCollection)

        {

            DataRow dr = dt.NewRow();

            dr["Name"] = MO["Name"].ToString();

            dr["BorderWidth"] = MO["BorderWidth"].ToString();

            dr["CursorBlinkRate"] = MO["CursorBlinkRate"];

            dr["DragFullWindows"] = MO["DragFullWindows"];

            dr["IconTitleFaceName"] = MO["IconTitleFaceName"];

            dr["IconTitleSize"] = MO["IconTitleSize"];

            dr["IconTitleWrap"] = MO["IconTitleWrap"];

            dr["Pattern"] = MO["Pattern"];

            dr["ScreenSaverActive"] = MO["ScreenSaverActive"];

            dr["WallpaperStretched"] = MO["WallpaperStretched"];

            dt.Rows.Add(dr);

        }

        GridView1.DataSource = dt;

        GridView1.DataBind();

    }

}

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

SelectQuery

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

ManagementObjectSearcher

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.

ManagementObjectCollection

It represents various collections of management objects retrieved using WMI.

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

Desktop-Details-of-your-Windows-Operating-System-5.jpg

Up Next
    Ebook Download
    View all
    Learn
    View all