Solved

Computer CPU/Memory usage

Posted on 2010-08-29
2
1,133 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

Portable, direct connect server access

The ATEN CV211 connects a laptop directly to any server allowing you instant access to perform data maintenance and local operations, for quick troubleshooting, updating, service and repair.

Question has a verified solution.

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

A project that enables an administrator to perform actions within a user session context not just at the time of login but any time later on day(s) or week(s) later.
This article shows how to use a free utility called 'Parkdale' to easily test the performance and benchmark any Hard Drive(s) installed in your computer. We also look at RAM Disks and their speed comparisons.
This video Micro Tutorial explains how to clone a hard drive using a commercial software product for Windows systems called Casper from Future Systems Solutions (FSS). Cloning makes an exact, complete copy of one hard disk drive (HDD) onto another d…
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.

728 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