Computer CPU/Memory usage

Posted on 2010-08-29
Last Modified: 2012-05-10
is there a way, beside using WMI, to know the total Cpu % used and memory % used?

If not, do you have a code example using WMI?

I remember working with WMI in the past, but it was working on some computer and not working on other(returning empty information). Im not sure exactly what are the requirements for WMI to work on Windows XP and recent OS(vista, 7).

Thanks in advance!
Question by:Enill
LVL 16

Accepted Solution

Vikram Singh Saini earned 500 total points
ID: 33554003

is there a way,  beside using WMI, to know the total Cpu % used and memory % used?

Check attach code ITEM-1.

Also visit links:





(5) (Reference for PerformanceCounter)

If not, do you have  a code example using WMI?



(2) (

(3) (CPU Usage in MultiProcessor machine).

(4) (For memory usage)

I remember working  with WMI in the past, but it was working on some computer and not  working on other(returning empty information). Im not sure exactly  what are the requirements for WMI to work on Windows XP and recent  OS(vista, 7).

Link explaining reason of slow working on Windows 7:

Link for WMI Code Creator:

// CPU & Memory Usage by using PerformanceCounter
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace CPU__MemoryCounter
    public partial class Form1 : Form
        PerformanceCounter cpuCounter;
        PerformanceCounter ramCounter;
        public Form1()

        private void timer1_Tick(object sender, EventArgs e)
            this.btnShow_Click(this, null);

        private void btnShow_Click(object sender, EventArgs e)
            cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");          

            ramCounter = new PerformanceCounter("Memory", "Available MBytes");

            richTextBox1.Text = "CPU Use: "+getCurrentCpuUsage() + "\n" + "RAM Used: "+ getAvailableRAM();

        public string getCurrentCpuUsage()
            string cpu= cpuCounter.NextValue() + "%";
            return cpu;

        public string getAvailableRAM()
            string ram;
            int ramAvailable = Convert.ToInt32(ramCounter.NextValue());
            int ramUsed = 1024 - ramAvailable; //1024 if 1GB RAM
            return ram=ramUsed.ToString()+"MB";


Open in new window


Author Comment

ID: 33554617
Thanks, ill give it a look.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Fatal Error 11 41
How to capture software 9 51
Input parameteres to DragOver 2 20
custom authorization on controller action and HTML in mvc 1 29
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In this video, we discuss why the need for additional vertical screen space has become more important in recent years, namely, due to the transition in the marketplace of 4x3 computer screens to 16x9 and 16x10 screens (so-called widescreen format). …
With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question