------------------------------------------------------
C# WMI开发,怎么取到
每秒钟页读取数 (pages/s)
Physical disk %disk time 磁盘时间,磁盘读写服务效率 ------------------------------------------------------用C#开发,取得CPU使用率,网络流量信息等等,很容易取到,但怎么取到“每秒钟页读取数”,“磁盘时间”,请高手指点?
C# WMI开发,怎么取到
每秒钟页读取数 (pages/s)
Physical disk %disk time 磁盘时间,磁盘读写服务效率 ------------------------------------------------------用C#开发,取得CPU使用率,网络流量信息等等,很容易取到,但怎么取到“每秒钟页读取数”,“磁盘时间”,请高手指点?
http://msdn.microsoft.com/zh-cn/library/system.diagnostics.performancecounter(v=vs.80).aspx
也可以远程访问,不过需要设置权限。http://haishibai.blogspot.com/2010/02/tiy-collect-remote-performance-counters.html
(需要代理才能访问)
................................
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Security.Principal;
using System.Runtime.InteropServices;namespace CPUCounterTest
{
class Program
{
public const int LOGON32_LOGON_INTERACTIVE = 2;
public const int LOGON32_LOGON_SERVICE = 3;
public const int LOGON32_PROVIDER_DEFAULT = 0; [DllImport("advapi32.dll", CharSet=CharSet.Auto)]
public static extern bool LogonUser(
String lpszUserName,
String lpszDomain,
String lpszPassword,
int dwLogonType,
int dwLogonProvider,
ref IntPtr phToken); [DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static bool CloseHandle(IntPtr handle); static void Main(string[] args)
{
IntPtr userHandle = new IntPtr(0);
LogonUser("UserA", "DomainA", "PasswordA", LOGON32_LOGON_INTERACTIVE, LOGON32_PROVIDER_DEFAULT, ref userHandle);
WindowsIdentity identity = new WindowsIdentity(userHandle);
WindowsImpersonationContext context = identity.Impersonate();
PerformanceCounterCategory cat = new PerformanceCounterCategory("Processor","MachineA");
List<PerformanceCounter> counters = new List<PerformanceCounter>();
foreach (string instance in cat.GetInstanceNames())
counters.Add(new PerformanceCounter("Processor", "% Processor Time", instance,"MachineA"));
for (int i = 0; i < 10000; i++)
{
foreach (PerformanceCounter counter in counters)
Console.Write(counter.NextValue() + " ");
}
context.Undo();
}
}
}
这个那个网页上的信息