none
Get CPU Usage for Remote Machine RRS feed

  • Question

  • I want know remote machine performance monitoring like Physical memory , CPU usage, processes , threads. using C#.
    Wednesday, June 9, 2010 9:47 AM

Answers

  • You can use below code for the same.

          PerformanceCounter cpuCounter;
          cpuCounter = new PerformanceCounter();
          cpuCounter.MachineName = "NI-25";
          cpuCounter.CategoryName = "Processor";
          cpuCounter.CounterName = "% Processor Time";
          cpuCounter.InstanceName = "_Total";
         
            String cpuUsage = cpuCounter.NextValue() + "%";
    Where NI-25 is machine name.
    Regards
    Nayan Paregi (MCTS)
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by Chennaiah R Tuesday, June 22, 2010 9:27 AM
    Wednesday, June 9, 2010 11:45 AM
  • Here is a sample

          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();
    Wednesday, June 9, 2010 11:56 AM

All replies

  • Hi, you need to look into WMI.
    Wednesday, June 9, 2010 10:49 AM
  • You can use below code for the same.

          PerformanceCounter cpuCounter;
          cpuCounter = new PerformanceCounter();
          cpuCounter.MachineName = "NI-25";
          cpuCounter.CategoryName = "Processor";
          cpuCounter.CounterName = "% Processor Time";
          cpuCounter.InstanceName = "_Total";
         
            String cpuUsage = cpuCounter.NextValue() + "%";
    Where NI-25 is machine name.
    Regards
    Nayan Paregi (MCTS)
    Please remember to click “Mark as Answer” on the post that helps you, and to click “Unmark as Answer” if a marked post does not actually answer your question. This can be beneficial to other community members reading the thread.
    • Marked as answer by Chennaiah R Tuesday, June 22, 2010 9:27 AM
    Wednesday, June 9, 2010 11:45 AM
  • Here is a sample

          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();
    Wednesday, June 9, 2010 11:56 AM
  • All this does is print the names of every single process running on the remote machine. How is this an answer?
    Monday, April 22, 2013 2:00 PM
  • it shows access is denied error
    Tuesday, January 6, 2015 5:29 AM
  • Not getting any result after run this script, Get Command prompt pop-up only.
    Friday, March 15, 2019 4:22 AM