I am trying to return the TimeStamp property using a wmi query and getting an object reference error. When I look in quickwatch, the property itself is null. I've seen examples of this on the web and can't figure out why this one property is teturning null while giving me everything else I query for.
I am using a windows 7 machine
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;
}