Solved

Computer CPU/Memory usage

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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

In this article, I will show you HOW TO: Install VMware Tools for Windows on a VMware Windows virtual machine on a VMware vSphere Hypervisor 6.5 (ESXi 6.5) Host Server, using the VMware Host Client. The virtual machine has Windows Server 2016 instal…
In this article, I will show you HOW TO: Perform a Physical to Virtual (P2V) Conversion the easy way from a computer backup (image).
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…
This Micro Tutorial will give you a basic overview of Windows DVD Burner through its features and interface. This will be demonstrated using Windows 7 operating system.

803 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