0

I am trying to create an application that pulls process information and puts it into a SQL table.

I am pulling Process Name, PID, CPU Time, Memory Usage, Page, and Handles.

Everything works fine except for the CPU Time. Here is the code I am using to get the CPU information:

Process[] processes = Process.GetProcesses(machineName);

foreach (Process p in processes)
{
    var cpuTime = p.TotalProcessorTime;
}

However I am getting this error:

Feature is not supported for remote machines.

Does anyone have any other way I can get this information and still be able to add it to my SQL table?

Matt
  • 1,220
  • 3
  • 21
  • 36

1 Answers1

4

How about using WMI ?

  string computerName="MyPc";
  System.Management.ManagementScope ms = new System.Management.ManagementScope(@"\\" + computerName + @"\root\cimv2");
  System.Management.SelectQuery sq = new System.Management.SelectQuery("SELECT * FROM Win32_Process");
  System.Management.ManagementObjectSearcher mos = new System.Management.ManagementObjectSearcher(ms,sq);
  foreach (System.Management.ManagementObject mo in mos.Get())
  {
    Console.WriteLine(mo["Name"].ToString());
  }
  Console.Read();
Lost_In_Library
  • 3,265
  • 6
  • 38
  • 70
  • That is what I started using but I don't know an easy way to compute CPU. I found a site that said if you take Kernel time and User time and do some math, you can get the CPU time. There has got to be an easier way to accomplish this. – Matt Jan 16 '12 at 22:52