Skip navigation

WMI in .NET

Take a Close Look at Your System’s Performance

asp:Feature

LANGUAGES: C#

ASP.NET VERSIONS: 2.0

 

WMI in .NET

Take a Close Look at Your System s Performance

 

By Joydip Kanjilal

 

Windows Management Instrumentation (WMI) is a Microsoft technology that enables us to retrieve system-related information. It is efficient in retrieving both hardware-related and software-related information from a computer system. Using WMI, one can communicate with the Windows OS, the hardware devices, running processes, COM+ components, etc. The objective of this article is to provide the reader with a bird s eye view of WMI, as well as a primer on its applicability.

 

What Is WMI?

Windows Management Instrumentation (WMI) is a technology that allows a robust, low-level communication with the Windows Operating System from Microsoft development environments. It can portray all details related to the hardware specifications of a computer system. It should be noted that the WMI classes are types defined using an abstract language called MOF (Managed Object Format) that predates the CLR. One can query for WMI data using the Windows Management Instrumentation Query Language (WQL), a subset of the American National Standard Query Language (ANSI SQL).

The following is an example of a WQL query:

 

SELECT * FROM Win32_Processor

 

Why WMI?

WMI is an extremely powerful technology that can be used to retrieve and monitor the system. It can be used in any of the following scenarios:

  • Retrieve hardware specifications and the Win 32 OS specifications for a system
  • Determine the CPU and memory load factors in a system
  • Work with performance counters to monitor application performance in a managed environment
  • Create applications for working with Mobile devices
  • Event notification and configuration management in distributed computing environments

 

Working with WMI in ASP.NET

WMI can be used in ASP.NET applications to track the application s performance; it is supported by the following namespaces:

  • System.Diagnostics
  • System.Management
  • System.Management.Instrumentation

 

There are many classes and interfaces in the System.Diagnostics, System.Management, and System.Management.Instrumentation namespaces that can be used for reading WMI data.

 

Monitoring Performance

Performance Counters are used to retrieve performance-related information in the system. They can be used to monitor and manage the system s details. They are organized by the following:

  • Category
  • Counter Name
  • Instance Name

 

The System.Diagnostics.PerformanceCounter class can be used to retrieve a variety of details related to the system s hardware and OS details. As an example, we can retrieve the % CPU time using this code snippet:

 

PerformanceCounter performanceCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");

int requiredValue = performanceCounter.NextValue();

 

Note that the constructor of the PerformanceCounter class accepts the arguments as stated earlier. We can list the various performance counters by using the perfmon.exe tool and then selecting the Add Tool option. Moreover, VS.NET includes support for displaying performance counters using the Server Explorer.

 

Conclusion

There is a lot to the WMI architecture, including performance counters, event notifications, configuration management, and storage, all built for a distributed environment which makes WMI the preferred technology for monitoring applications on the Windows platform.

 

Working extensively in Microsoft technologies for more than 10 years, Joydip Kanjilal is a Senior Project Leader for a company in Hyderabad, India. His programming skills include C, C++, Java, C#, VB, VC++, ASP.NET, XML, and UML. He has worked with .NET and C# for more than five years. Reach Joydip at mailto:[email protected].

 

 

 

 

Hide comments

Comments

  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
Publish