Help with a Win32: Access is Denied exception in C#

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • inlovewithmusic
    New Member
    • Nov 2006
    • 14

    Help with a Win32: Access is Denied exception in C#

    Hello,

    I am trying to write an application that gets the amount of CPU that a process is using , its throwing an a Win 32 exception that says Access is denied to the UserProcessorTi me property ....enclosed is the code , any way that i can resolve this and access the property ?


    Code:
    using System;
    using System.Collections.Generic;
    using System.Text;
    using System.Diagnostics;
    namespace ConsoleApplication2
    {
        class Program
        {
            static void Main(string[] args)
            {
                execute();
    
            }
            
            public static void execute()
            {
                Process[] currentProcess = Process.GetProcesses();
    
                string[] processes = new string[currentProcess.Length];
    
                int k = 0;
                while (k < currentProcess.Length)
                {
                    processes[k] = currentProcess[k].Id + " " + currentProcess[k].ProcessName + " " + currentProcess[k].WorkingSet64 + " " + currentProcess[k].Threads.Count + " " + currentProcess[k].UserProcessorTime;
    
                    ++k;
                }
    
                System.Console.ReadLine();
                            
            }
    
         }
    }
    Last edited by Curtis Rutland; Jul 31 '08, 03:25 AM. Reason: Added code tags -- Please use the # button
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Two of the process's can't be checked for a number of values ( "System Idle Proccess" and "system" I think are the two)
    Just check for exceptions and you should be fine.

    Comment

    Working...