get CPU usage (like in task manager) and FreePhysicalMemory

A

Avi G

Hi,

I've no experience in csharp and i search for scripts over the net for find
the current cpu usage like in task manager (for all processors ) when i run
it and another script that show the current Free Physical Memory.

THX
 
M

Michael Soza

you can use wmi...
for example Win32_OperatingSystem offers some useful information:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Management;

namespace memory
{
class Program
{
static void Main(string[] args)
{
var query = new ObjectQuery("SELECT * FROM
Win32_OperatingSystem");
ManagementObjectSearcher searcher = new
ManagementObjectSearcher(query);
foreach (ManagementObject item in searcher.Get())
{
Console.WriteLine("FreePhysicalMemory:" +
item["FreePhysicalMemory"]);
Console.WriteLine("FreeVirtualMemory:" +
item["FreeVirtualMemory"]);
}
Console.Read();
}
}
}

for the thing of cpu usage obviously must exist some wmi class that has that
information....take a look in msdn in the section of wmi classes

Michael Soza.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top