获取系统如cpu、内存、硬盘、网络等的实时情况

wj0728 2010-10-28 12:03:26
要获取系统的这些信息,在不使用wmi服务的情况下进行操作,因为这个服务可能运行不正常,这样就会导致数据无法采集,除了性能计数器之外还可以用什么方式进行数据的采集,kernel32.dll这个类库运行是否基于windows的服务,知道的朋友麻烦指点一下,谢谢。
还有就是性能计数器的计数类型有哪些?
如"Processor", "% Processor Time", "_Total"
"Process", "Working Set", "_Total"
...全文
427 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
wuyq11 2010-10-28
  • 打赏
  • 举报
回复
DriveInfo[] drivers = DriveInfo.GetDrives();
PerformanceCounter cpuCounter;
PerformanceCounter ramCounter;
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "";

[DllImport("IpHlpApi.dll")]
extern static public uint GetIfTable(byte[] pIfTable, ref uint pdwSize, bool bOrder);来获取本机网络信息
http://www.philosophicalgeek.com/2009/01/03/determine-cpu-usage-of-current-process-c-and-c/
porschev 2010-10-28
  • 打赏
  • 举报
回复
看看。。。。
bloodish 2010-10-28
  • 打赏
  • 举报
回复
其他一些信息
NetworkInterface.GetIsNetworkAvailable();
DriveInfo.GetDrives();
bloodish 2010-10-28
  • 打赏
  • 举报
回复
internal 请改成 public,写错了.
bloodish 2010-10-28
  • 打赏
  • 举报
回复

[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_INFO
{
internal int dwOemId;
internal int dwPageSize;
internal IntPtr lpMinimumApplicationAddress;
internal IntPtr lpMaximumApplicationAddress;
internal IntPtr dwActiveProcessorMask;
internal int dwNumberOfProcessors;
internal int dwProcessorType;
internal int dwAllocationGranularity;
internal short wProcessorLevel;
internal short wProcessorRevision;
}

[DllImport("kernel32.dll", SetLastError=true)]
public static extern void GetSystemInfo(ref SYSTEM_INFO lpSystemInfo);

wj0728 2010-10-28
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bloodish 的回复:]
C# code

[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_INFO
{
internal int dwOemId;
internal int dwPageSize;
internal IntPtr lpMinimumApplicationAddress;
internal ……
[/Quote]

这种模式是基于什么的啊?
wj0728 2010-10-28
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 wuyq11 的回复:]
DriveInfo[] drivers = DriveInfo.GetDrives();
PerformanceCounter cpuCounter;
PerformanceCounter ramCounter;
cpuCounter = new PerformanceCounter();
cpuCounter.CategoryName = "";

[DllImport("IpHlp……
[/Quote]

都可以通过performancecounter来获取
PerformanceCounter pfc = new PerformanceCounter("Processor", "% Processor Time", "_Total");
PerformanceCounter networkReceivePerformance = new PerformanceCounter("Network Interface", "Bytes Received/sec", "Realtek PCIe FE Family Controller");
PerformanceCounter networkSendPerformance = new PerformanceCounter("Network Interface", "Bytes Sent/sec", "Realtek PCIe FE Family Controller");
PerformanceCounter diskPerformance = new PerformanceCounter("LogicalDisk", "% Free Space", "_Total");
PerformanceCounter memoryPerformance = new PerformanceCounter("Memory", "Available MBytes");
xy325432 2010-10-28
  • 打赏
  • 举报
回复
不会!!!
帮顶!!!
loveyan52112 2010-10-28
  • 打赏
  • 举报
回复
string strResult;

ManagementClass diskClass = new ManagementClass( "Win32_LogicalDisk ");

ManagementObjectCollection disks;
disks = diskClass.GetInstances();
foreach( ManagementObject disk in disks)
{
strResult = " ";

strResult += "设备ID: " + disk[ "DeviceID "];

strResult += "磁盘名称: " + disk[ "Name "];

strResult += "磁盘卷标: " + disk[ "VolumeName "];

if( disk[ "FileSystem "].ToString() != " " )
{
strResult += "文件系统: " + disk[ "FileSystem "];

strResult += "磁盘描述: " + disk[ "Description "];

if( System.Convert.ToInt64(disk[ "Size "]) > 0 )
{
strResult += "磁盘大小: " + System.Convert.ToInt64(disk[ "Size "].ToString());
}
strResult += "磁盘类型: " + System.Convert.ToInt16(disk[ "DriveType "].ToString());
}
Response.Write(strResult);
}
lqkankan 2010-10-28
  • 打赏
  • 举报
回复
deyygywxf 2010-10-28
  • 打赏
  • 举报
回复
[StructLayout(LayoutKind.Sequential)]
public struct SYSTEM_INFO
{
internal int dwOemId;
internal int dwPageSize;
internal IntPtr lpMinimumApplicationAddress;
internal IntPtr lpMaximumApplicationAddress;
internal IntPtr dwActiveProcessorMask;
internal int dwNumberOfProcessors;
internal int dwProcessorType;
internal int dwAllocationGranularity;
internal short wProcessorLevel;
internal short wProcessorRevision;
}

[DllImport("kernel32.dll", SetLastError=true)]
public static extern void GetSystemInfo(ref SYSTEM_INFO lpSystemInfo);

110,580

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧