WMI in .NET

Take a Close Look at Your System’s Performance

Joydip Kanjilal

October 30, 2009

3 Min Read
ITPro Today logo

asp:Feature

LANGUAGES:C#

ASP.NETVERSIONS: 2.0

 

WMI in .NET

Take a Close Look at Your System s Performance

 

By Joydip Kanjilal

 

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

 

What Is WMI?

Windows Management Instrumentation (WMI) is a technologythat allows a robust, low-level communication with the Windows Operating Systemfrom Microsoft development environments. It can portray all details related tothe hardware specifications of a computer system. It should be noted that theWMI classes are types defined using an abstract language called MOF (ManagedObject Format) that predates the CLR. One can query for WMI data using theWindows Management Instrumentation Query Language (WQL), a subset of theAmerican 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 usedto retrieve and monitor the system. It can be used in any of the followingscenarios:

  • Retrieve hardware specifications and the Win 32OS specifications for a system

  • Determine the CPU and memory load factors in asystem

  • Work with performance counters to monitorapplication performance in a managed environment

  • Create applications for working with Mobiledevices

  • Event notification and configuration managementin distributed computing environments

 

Working with WMI in ASP.NET

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

  • System.Diagnostics

  • System.Management

  • System.Management.Instrumentation

 

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

 

Monitoring Performance

Performance Counters are used to retrieve performance-relatedinformation in the system. They can be used to monitor and manage the system sdetails. They are organized by the following:

  • Category

  • Counter Name

  • Instance Name

 

The System.Diagnostics.PerformanceCounter class can beused 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 = newPerformanceCounter("Processor", "% Processor Time","_Total");

int requiredValue = performanceCounter.NextValue();

 

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

 

Conclusion

There is a lot to the WMI architecture, includingperformance counters, event notifications, configuration management, andstorage, all built for a distributed environment which makes WMI the preferredtechnology for monitoring applications on the Windows platform.

 

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

 

 

 

 

Read more about:

Microsoft
Sign up for the ITPro Today newsletter
Stay on top of the IT universe with commentary, news analysis, how-to's, and tips delivered to your inbox daily.

You May Also Like