我正在尝试使用 wmi 查询返回 TimeStamp 属性并获取对象引用错误。当我查看 quickwatch 时,属性本身为空。我在网上看到过这样的例子,但无法弄清楚为什么这个属性在给我查询的所有其他内容的同时返回 null。
我正在使用 Windows 7 机器
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;
}