C# 时间戳\u Sys100NS从Win32\u PerfFormattedData\u PerfProc\u进程wmi返回null
我正在尝试使用wmi查询返回TimeStamp属性,并得到一个对象引用错误。当我查看quickwatch时,属性本身为null。我在网上看到过这样的例子,但我不明白为什么这一属性在为我查询其他所有内容的同时却变成null 我使用的是Windows7机器C# 时间戳\u Sys100NS从Win32\u PerfFormattedData\u PerfProc\u进程wmi返回null,c#,wmi,wmi-query,wmi-service,C#,Wmi,Wmi Query,Wmi Service,我正在尝试使用wmi查询返回TimeStamp属性,并得到一个对象引用错误。当我查看quickwatch时,属性本身为null。我在网上看到过这样的例子,但我不明白为什么这一属性在为我查询其他所有内容的同时却变成null 我使用的是Windows7机器 public List<string> ReturnProcesses() { string processname; ulong N1 = 0; ulong D1 =
public List<string> ReturnProcesses()
{
string processname;
ulong N1 = 0;
ulong D1 = 0;
ulong N2 = 0;
ulong D2 = 0;
ConnectionOptions options = new ConnectionOptions();
options.Impersonation = ImpersonationLevel.Impersonate;
List<string> Processlist = new List<string>();
ManagementScope scope = new ManagementScope("\\root\\cimv2");
scope.Connect();
ObjectQuery query = new ObjectQuery("SELECT IDProcess,Name,PrivateBytes,PercentProcessorTime,TimeStamp_Sys100NS FROM Win32_PerfFormattedData_PerfProc_Process");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
ManagementObjectCollection queryCollection = searcher.Get();
try
{
foreach (ManagementObject mo in queryCollection)
{
ulong privbytes = (ulong.Parse(mo["PrivateBytes"].ToString()) / 1024);
processname = mo["IDProcess"].ToString() + " " + mo["Name"].ToString() + " " + mo["PercentProcessorTime"].ToString() + " " + privbytes.ToString();
N2 = ulong.Parse(mo["PercentProcessorTime"].ToString());
D2 = ulong.Parse(mo["TimeStamp_Sys100NS"].ToString());
Processlist.Add(processname);
}
}
catch (Exception ex)
{
throw ex;
}
return Processlist;
}
公共列表返回进程()
{
字符串进程名;
ulong N1=0;
ulong D1=0;
ulong N2=0;
乌隆D2=0;
ConnectionOptions选项=新的ConnectionOptions();
options.Impersonation=ImpersonationLevel.Impersonate;
List Processlist=新列表();
ManagementScope范围=新的ManagementScope(\\root\\cimv2”);
scope.Connect();
ObjectQuery query=new ObjectQuery(“从Win32中选择IDProcess、Name、PrivateBytes、PercentProcessorTime、TimeStamp_Sys100NS\u PerfFormattedData\u PerfProc_Process”);
ManagementObjectSearcher search=新的ManagementObjectSearcher(范围、查询);
ManagementObjectCollection queryCollection=searcher.Get();
尝试
{
foreach(queryCollection中的ManagementObject任务单)
{
ulong PrivateBytes=(ulong.Parse(mo[“PrivateBytes”].ToString())/1024);
processname=mo[“IDProcess”].ToString()+“”+mo[“Name”].ToString()+“”+mo[“PercentProcessorTime”].ToString()+“”+privbytes.ToString();
N2=ulong.Parse(mo[“PercentProcessorTime”].ToString());
D2=ulong.Parse(mo[“TimeStamp_Sys100NS”].ToString());
Processlist.Add(processname);
}
}
捕获(例外情况除外)
{
掷骰子;
}
返回进程列表;
}
您需要使用Win32\uPerfRawData\uPerfProc\u进程
而不是Win32\uPerfFormattedData\uPerfProc\u进程