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

Introduction

This article describes how to get the details of your Windows Operating System. Here I will get the information from the Win32_OperatingSystem class.

Win32_OperatingSystem

The Win32_OperatingSystem WMI Class represents a Windows-based operating system installed on a computer. Any operating system that can be installed on a computer that can run a Windows-based operating system is a descendent or member of this class. Win32_OperatingSystem is a singleton class.

If a computer has multiple operating systems installed then this class only returns an instance for the currently active operating system.

Design

Create a new ASP.Net Empty website.

Add one page in that website.

Write the following source code:
  1. <head runat="server">  
  2.     <title></title>  
  3.     <style type="text/css">  
  4.         html  
  5.         {  
  6.             font-size: 1.5em;  
  7.             font-family: Calibri;  
  8.             color: Red;  
  9.         }  
  10.     </style>  
  11. </head>  
  12. <body>  
  13.     <form id="form1" runat="server">  
  14.     <div>  
  15.     </div>  
  16.     </form>  
  17. </body>  
  18. </html>
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.

2.png

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

3.jpeg

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. public partial class _Default : System.Web.UI.Page  
  9. {  
  10.     protected void Page_Load(object sender, EventArgs e)  
  11.     {  
  12.         SelectQuery Sq = new SelectQuery("Win32_OperatingSystem");  
  13.         ManagementObjectSearcher objOSDetails = new ManagementObjectSearcher(Sq);  
  14.         ManagementObjectCollection osDetailsCollection = objOSDetails.Get();  
  15.         foreach (ManagementObject mo in osDetailsCollection)  
  16.         {  
  17.             Response.Write("Name : " + mo["name"].ToString() + "<br/>");  
  18.             Response.Write("Version : " + mo["version"].ToString() + "<br/>");  
  19.             Response.Write("Csname : " + mo["csname"].ToString() + "<br/>");  
  20.             Response.Write("Boot Device : " + mo["BootDevice"].ToString() + "<br/>");  
  21.             Response.Write("Build Number : " + mo["BuildNumber"].ToString() + "<br/>");  
  22.             Response.Write("BuildType : " + mo["BuildType"].ToString() + "<br/>");  
  23.             Response.Write("Caption : " + mo["Caption"].ToString() + "<br/>");  
  24.             Response.Write("CodeSet : " + mo["CodeSet"].ToString() + "<br/>");  
  25.             Response.Write("CountryCode : " + mo["CountryCode"].ToString() + "<br/>");  
  26.             Response.Write("CreationClassName : " + mo["CreationClassName"].ToString() + "<br/>");  
  27.             Response.Write("CSCreationClassName : " + mo["CSCreationClassName"].ToString() + "<br/>");  
  28.             Response.Write("CSDVersion : " + mo["CSDVersion"].ToString() + "<br/>");  
  29.             Response.Write("CurrentTimeZone : " + mo["CurrentTimeZone"].ToString() + "<br/>");  
  30.             Response.Write("DataExecutionPrevention_Available : " + mo["DataExecutionPrevention_Available"].ToString() + "<br/>");  
  31.             Response.Write("DataExecutionPrevention_32BitApplications : " + mo["DataExecutionPrevention_32BitApplications"].ToString() +  
  32. "<br/>");  
  33.             Response.Write("DataExecutionPrevention_Drivers : " + mo["DataExecutionPrevention_Drivers"].ToString() + "<br/>");  
  34.             Response.Write("DataExecutionPrevention_SupportPolicy : " + mo["DataExecutionPrevention_SupportPolicy"].ToString() + "<br/>");  
  35.             Response.Write("Debug : " + mo["Debug"].ToString() + "<br/>");  
  36.             Response.Write("Description : " + mo["Description"].ToString() + "<br/>");  
  37.             Response.Write("Distributed : " + mo["Distributed"].ToString() + "<br/>");  
  38.             Response.Write("EncryptionLevel : " + mo["EncryptionLevel"].ToString() + "<br/>");  
  39.             Response.Write("ForegroundApplicationBoost : " + mo["ForegroundApplicationBoost"].ToString() + "<br/>");  
  40.             Response.Write("FreePhysicalMemory : " + mo["FreePhysicalMemory"].ToString() + "<br/>");  
  41.             Response.Write("FreeSpaceInPagingFiles : " + mo["FreeSpaceInPagingFiles"].ToString() + "<br/>");  
  42.             Response.Write("FreeVirtualMemory : " + mo["FreeVirtualMemory"].ToString() + "<br/>");  
  43.             Response.Write("InstallDate : " + mo["InstallDate"].ToString() + "<br/>");  
  44.             Response.Write("LastBootUpTime : " + mo["LastBootUpTime"].ToString() + "<br/>");  
  45.             Response.Write("LocalDateTime : " + mo["LocalDateTime"].ToString() + "<br/>");  
  46.             Response.Write("Locale : " + mo["Locale"].ToString() + "<br/>");  
  47.             Response.Write("Manufacturer : " + mo["Manufacturer"].ToString() + "<br/>");  
  48.             Response.Write("MaxNumberOfProcesses : " + mo["MaxNumberOfProcesses"].ToString() + "<br/>");  
  49.             Response.Write("MaxProcessMemorySize : " + mo["MaxProcessMemorySize"].ToString() + "<br/>");  
  50.             Response.Write("NumberOfProcesses : " + mo["NumberOfProcesses"].ToString() + "<br/>");                           
  51.             Response.Write("NumberOfUsers : " + mo["NumberOfUsers"].ToString() + "<br/>");  
  52.             Response.Write("OperatingSystemSKU : " + mo["OperatingSystemSKU"].ToString() + "<br/>");  
  53.             Response.Write("Organization : " + mo["Organization"].ToString() + "<br/>");  
  54.             Response.Write("OSArchitecture : " + mo["OSArchitecture"].ToString() + "<br/>");  
  55.             Response.Write("OSLanguage : " + mo["OSLanguage"].ToString() + "<br/>");  
  56.             Response.Write("OSType : " + mo["OSType"].ToString() + "<br/>");  
  57.             Response.Write("PAEEnabled : " + mo["PAEEnabled"].ToString() + "<br/>");  
  58.             Response.Write("Primary : " + mo["Primary"].ToString() + "<br/>");  
  59.             Response.Write("ProductType : " + mo["ProductType"].ToString() + "<br/>");  
  60.             Response.Write("RegisteredUser : " + mo["RegisteredUser"].ToString() + "<br/>");  
  61.             Response.Write("SerialNumber : " + mo["SerialNumber"].ToString() + "<br/>");  
  62.             Response.Write("ServicePackMajorVersion : " + mo["ServicePackMajorVersion"].ToString() + "<br/>");  
  63.             Response.Write("ServicePackMinorVersion : " + mo["ServicePackMinorVersion"].ToString() + "<br/>");  
  64.             Response.Write("SizeStoredInPagingFiles : " + mo["SizeStoredInPagingFiles"].ToString() + "<br/>");  
  65.             Response.Write("Status : " + mo["Status"].ToString() + "<br/>");  
  66.             Response.Write("SuiteMask : " + mo["SuiteMask"].ToString() + "<br/>");  
  67.             Response.Write("SystemDevice : " + mo["SystemDevice"].ToString() + "<br/>");  
  68.             Response.Write("SystemDirectory : " + mo["SystemDirectory"].ToString() + "<br/>");  
  69.             Response.Write("SystemDrive : " + mo["SystemDrive"].ToString() + "<br/>");  
  70.             Response.Write("TotalVirtualMemorySize : " + mo["TotalVirtualMemorySize"].ToString() + "<br/>");  
  71.             Response.Write("TotalVisibleMemorySize : " + mo["TotalVisibleMemorySize"].ToString() + "<br/>");  
  72.             Response.Write("Version : " + mo["Version"].ToString() + "<br/>");  
  73.             Response.Write("WindowsDirectory : " + mo["WindowsDirectory"].ToString() + "<br/>");  
  74.         }  
  75.     }  
  76. }
In the code above I get the information from Win32_OperatingSystem and display that in the page.

SelectQuery

It represents a WMI Query Language (WQL) 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 the details of your Windows OS in the page.

5.jpeg


Similar Articles