Solved

Computer CPU/Memory usage

Posted on 2010-08-29
2
1,129 Views
Last Modified: 2012-05-10
Hi,
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!
0
Comment
Question by:Enill
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 16

Accepted Solution

by:
Vikram Singh Saini earned 500 total points
ID: 33554003
Hi,

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

Check attach code ITEM-1.

Also visit links:

(1) http://www.geekpedia.com/tutorial211_Using-Performance-Counters-in-Csharp.html

(2) http://www.codeproject.com/KB/system/processescpuusage.aspx

(3) http://www.codeproject.com/kb/system/cpuusageByDudiAvramov.aspx

(4) http://social.msdn.microsoft.com/forums/en-US/winforms/thread/06b215f1-c6a6-4ebb-ba4e-d17484308741/

(5) http://msdn.microsoft.com/en-us/library/system.diagnostics.performancecounter%28VS.90%29.aspx (Reference for PerformanceCounter)

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

Link:

(1) http://www.computerperformance.co.uk/vbscript/wmi_memory.htm

(2) (http://www.experts-exchange.com/Programming/Misc/Q_20927135.html

(3) http://www.codeproject.com/KB/system/MultiCPUUsage.aspx (CPU Usage in MultiProcessor machine).

(4) http://www.codeproject.com/KB/cs/System_Meter.aspx (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:

http://www.paessler.com/manuals/prtg7/wmi_sensors.htm

Link for WMI Code Creator: http://micksmix.wordpress.com/2010/02/02/the-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()
        {
            InitializeComponent();
        }

        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

0
 

Author Comment

by:Enill
ID: 33554617
Thanks, ill give it a look.
0

Featured Post

Create the perfect environment for any meeting

You might have a modern environment with all sorts of high-tech equipment, but what makes it worthwhile is how you seamlessly bring together the presentation with audio, video and lighting. The ATEN Control System provides integrated control and system automation.

Question has a verified solution.

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

An article on effective troubleshooting
Configuring Remote Assistance for use with SCCM
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Finding and deleting duplicate (picture) files can be a time consuming task. My wife and I, our three kids and their families all share one dilemma: Managing our pictures. Between desktops, laptops, phones, tablets, and cameras; over the last decadeā€¦

734 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