?
Solved

Computer CPU/Memory usage

Posted on 2010-08-29
2
Medium Priority
?
1,140 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article is a collection of issues that people face from time to time and possible solutions to those issues. I hope you enjoy reading it.
Windows 10 Creator Update has just been released and I have it working very well on my laptop. Read below for issues, fixes and ideas.
The viewer will learn how to successfully create a multiboot device using the SARDU utility on Windows 7. Start the SARDU utility: Change the image directory to wherever you store your ISOs, this will prevent you from having 2 copies of an ISO wit…
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…

770 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