Click here to Skip to main content
15,743,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to write a code to counting all the process machine and the time spent by me on each process.

When i start to debug the following code below an exception has throw when i try to get the processStartTime.

The message is "Acess Denied".

p.StartTime 'p.StartTime' threw an exception of type 'System.ComponentModel.Win32Exception'

   em System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 access, Boolean throwIfExited)
   em System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited)
   em System.Diagnostics.Process.GetProcessTimes()
   em System.Diagnostics.Process.get_StartTime()

Anyone can help me ?

Best regards

var list = System.Diagnostics.Process.GetProcesses();
           foreach (var p in list)
               System.Diagnostics.PerformanceCounter pc = new System.Diagnostics.PerformanceCounter();

               string processStartTime = string.Empty;
               if (p.StartTime != null)
                   processStartTime = p.StartTime.ToString();
               listbox1.Items.Add(p.ProcessName + " MainWindowHandle: " + p.MainWindowTitle + " process start time: " + processStartTime);
Updated 15-Nov-22 1:03am

1.You should have Administrator rights in order to can access the process info.

2.The solution is to run your application "As Administrator".
Share this answer
Leonardo Metre 26-Aug-14 2:17am    
when the ProcessName is "Idle" the same exception fires
Replace the your application manifest with the following lines
<requestedexecutionlevel level="requireAdministrator" uiaccess="false">
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900