code_junkie

Process.StartTime Access Denied

Nov 10th, 2011
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. using System.Management;
  2. String queryString = "select CreationDate from Win32_Process where ProcessId='" + ProcessId + "'";
  3. SelectQuery query = new SelectQuery(queryString);
  4.  
  5. ManagementScope scope = new System.Management.ManagementScope(@"\.rootCIMV2");
  6. ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);
  7. ManagementObjectCollection processes = searcher.Get();
  8.  
  9. //... snip ... logic to figure out which of the processes in the collection is the right one goes here
  10.  
  11. DateTime startTime = ManagementDateTimeConverter.ToDateTime(processes[0]["CreationDate"].ToString());
  12. TimeSpan uptime = DateTime.Now.Subtract(startTime);
Add Comment
Please, Sign In to add comment