1. 程式人生 > >c#監測電腦狀態

c#監測電腦狀態

physical available closed pub opened ram ava pro esp

原文: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#監測電腦狀態