c#监测电脑状态

2021-04-20 05:30

阅读:481

标签:monit   value   tor   sea   ado   logs   from   sel   isp   

原文:c#监测电脑状态

技术分享图片技术分享图片
 1 public class DeviceMonitor
 2     {
 3 
 4         static readonly PerformanceCounter cpuCounter = new PerformanceCounter("Processor", "% Processor Time", "_Total");
 5         static readonly PerformanceCounter ramCounter = new PerformanceCounter("Memory", "Available MBytes");
 6         static readonly PerformanceCounter uptime = new PerformanceCounter("System", "System Up Time");
 7 
 8 
 9         public static bool GetInternetAvilable()
10         {
11             bool networkUp = System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable();
12             return networkUp;
13         }
14 
15         public static TimeSpan GetSystemUpTime()
16         {
17             uptime.NextValue();
18             TimeSpan ts = TimeSpan.FromSeconds(uptime.NextValue());
19             return ts;
20         }
21 
22         public static string GetPhysicalMemory()
23         {
24             string str = null;
25             ManagementObjectSearcher objCS = new ManagementObjectSearcher("SELECT * FROM Win32_ComputerSystem");
26             foreach (ManagementObject objMgmt in objCS.Get())
27             {
28                 str = objMgmt["totalphysicalmemory"].ToString();
29             }
30             return str;
31         }
32 
33         public static string getCurrentCpuUsage()
34         {
35             return cpuCounter.NextValue() + "%";
36         }
37 
38         public static string getAvailableRAM()
39         {
40             return ramCounter.NextValue() + "MB";
41         }
42     }
View Code

c# 监测电脑状态,CPU使用率,物理内存使用,开机时间,网络状态

 

c#监测电脑状态

标签:monit   value   tor   sea   ado   logs   from   sel   isp   

原文地址:https://www.cnblogs.com/lonelyxmas/p/8628328.html


评论


亲,登录后才可以留言!