CPU Usage using WMI & C#

前端 未结 3 1874
后悔当初
后悔当初 2021-01-07 08:37

How can i retrieve the current CPU usage in c# using WMI? I\'ve seen plenty of posts using performance counters, but I need a solution that can work with remote machines. I\

3条回答
  •  醉酒成梦
    2021-01-07 08:48

    the tool "pslist" from sysinternals (its free) could readout the usage from remotemachines. y could start the programm within a cmd-box and fetch the result into your application.

            cmd.StartInfo.FileName = "cmd.com"; 
            cmd.StartInfo.Arguments = "/c pslist ....."; 
            cmd.StartInfo.RedirectStandardOutput = true; 
            cmd.StartInfo.RedirectStandardError  = true; 
    
            // run process and catch output 
            cmd.Start(); 
            string sOutput = cmd.StandardOutput.ReadToEnd(); 
            cmd.WaitForExit(); 
    

提交回复
热议问题