.net要实现这些东西一般也是通过平台调用实现了,api调用:
1.使用win32:
[DllImport("kernel32")]
public static extern void GetSystemDirectory(StringBuilder
SysDir,int count);
[DllImport("kernel32")]
public static extern void GetSystemInfo(ref CPU_INFO cpuinfo);
[DllImport("kernel32")]
public static extern void GlobalMemoryStatus(ref MEMORY_INFO
meminfo);
[DllImport("kernel32")]
public static extern void GetSystemTime(ref SYSTEMTIME_INFO
stinfo);
http://www.cnblogs.com/wlq2000/archive/2006/04/13/374247.html
2.使用性能计数器
你可以搜一下,很多
不用调用API,.NET已经封装好了,用下面这个就OK了,
((Environment.WorkingSet / 0x100000L)).ToString() ;//MB
下面的方法是获取系统的物理内存大小:
public static string GetPhisicalMemory()
{
ManagementObjectSearcher searcher = new ManagementObjectSearcher();
searcher.Query = new SelectQuery("Win32_PhysicalMemory", "", new string[] { "Capacity" });
ManagementObjectCollection.ManagementObjectEnumerator enumerator = searcher.Get().GetEnumerator();
double num = 0;
while (enumerator.MoveNext())
{
ManagementBaseObject current = enumerator.Current;
if (current.Properties["Capacity"].Value != null)
{
try
{
num += double.Parse(current.Properties["Capacity"].Value.ToString());
}
catch
{
return "δ֪";
}
}
}
num /= 0x100000;
num = Math.Abs(num / 1024);
return string.Format("{0}GB", num);
}