Click here to Skip to main content
15,880,427 members
Articles / Programming Languages / C#
Article

find out how processor load using wmi

Rate me:
Please Sign up or sign in to vote.
2.33/5 (2 votes)
25 Sep 2009CPOL2 min read 24K   640   10   3
Example of how to find out the processor load using wmi (windows management instrument)

Sample Image - maximum width is 600 pixels

Introduction

Example of how to find out the processor load using wmi (windows management instrument)
WMI is an administrative tool included with the windows systems. For administrators
with WMI access to all information of a pc, such as memory, hard disk, network card, processor, short quite easily without programming in Assembly to gain access to this information can be...
for more information about WMI can go to this address
http://technet2.microsoft.com/WindowsServer/es/Library/cc37ec96-9bd0-4c6a-8e5a-5805563a61b73082.mspx?mfr=true

Using the Code

To determine the processor load we must creates an instance of WMI and so use the member functions of object.
To create a WMI instacia be follows.

ManagementObject processor = new ManagementObject();

ManagementObject has several overloaded, constructore with miscellaneous parameter, in our case, we'll use in type string constructor and passing data you wish to have access to information, telling that we want to have the burden of processor and system information. In this way

ManagementObject processor = new ManagementObject( "Win32_PerfFormattedData_PerfOS_Processor.Name='_Total'") 

Win32_PerfFormattedData_PerfOS_Processor. It is a responsible for WMI classes of da charging system on the processor, through its Name property condition information passing finds it _Total we want the total value of the system overhead.

A view that we see a ManagementObject instance created will use the Get method of the ManagementObject classes for associated instance object created in this way

processor.Get();

in this way we can already calls to the method and properties in classes, in this case call the object properties that it will not return the value of the properties of the query object properties here will not return the percentage of processor time

processor.Properties["PercentProcessorTime"].Value;

to summarize all do so

ManagementObject processor = new ManagementObject(
"Win32_PerfFormattedData_PerfOS_Processor.Name='_Total'");

processor.Get();
processor.Properties["PercentProcessorTime"].Value;

as ye see the code short compared if we had used Assembly low-level by directly calling the bios is

to continuation or I will leave the code strong example as shown in this shot.

Sample Image - maximum width is 600 pixels

the code you can modify or distribute it only to do mensio author this program set yourselves in the following image is fine-tuning the code and them is converted into a sensor

Sample Image - maximum width is 600 pixels

space used name: using System.Management;
reference: System.Management.DLL

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Spain Spain
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralExactly what i was looking for! Pin
MatheusMK325-Jan-10 7:52
MatheusMK325-Jan-10 7:52 
GeneralMy vote of 1 Pin
Hotcut27-Sep-09 21:49
Hotcut27-Sep-09 21:49 
GeneralRe: My vote of 1 Pin
jesuli28-Sep-09 4:18
jesuli28-Sep-09 4:18 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.