Exception When Accessing Process.StartTime, Excep:"Access is Denied"
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 8 of 8

Thread: Exception When Accessing Process.StartTime, Excep:"Access is Denied"

  1. #1
    Join Date
    May 2006
    Location
    Islamabad
    Posts
    99

    Exception When Accessing Process.StartTime, Excep:"Access is Denied"

    Hi there,

    I have to get processes info for a system but I m having an Exception "Access is denied" in this code,
    Code:
    try
    {
         processes = Process.GetProcesses(mcName);
          int nThreadsCount = 0;
          foreach (Process p in processes)
          {
    
                    string[] prcDetails = new string[]{p.ProcessName,
                                                     p.Id.ToString(),
                                 // following statement causing exception
                                                     p.StartTime.ToShortTimeString(),
                                                   p.TotalProcessorTime.Duration).Hours.ToString()+":"+p.TotalProcessorTime.Duration().Minutes.ToString()+":"+p.TotalProcessorTime.Duration().Seconds.ToString(),
                                                      p.Threads.Count.ToString(),
                                                      p.HandleCount.ToString()};
    
                       nThreadsCount += p.Threads.Count; 
    
          }
    }
    catch (Exception ex)
    {
           MessageBox.Show(ex.Message); 
    }

    When I commented the statement
    p.StartTime.ToShortTimeString(),
    then next statement which is also getting-time-related property
    p.TotalProcessorTime.Duration().Hours.ToString()
    is also causing same exception.

    Here is the Sysem Trace:

    " at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 access, Boolean throwIfExited)\r\n at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfExited)\r\n at System.Diagnostics.Process.GetProcessTimes()\r\n at System.Diagnostics.Process.get_StartTime()\r\n at CustomizedTaskManager.frmmain.LoadAllProcessesOnStartup() in E:\\MyProjects\\Programing\\C#\\Task Manager\\CustomizedTaskManager\\CustomizedTaskManager\\Form1.cs:line 100"

    best regards,
    Cyber Friend

  2. #2
    Join Date
    Apr 2007
    Location
    Florida
    Posts
    403

    Re: Exception When Accessing Process.StartTime, Excep:"Access is Denied"

    Process.StartTime is a secure proprty.

    Process.StartTime can only be read if your logged on user is part of the Performance Log users group in computer management.

  3. #3
    Join Date
    May 2006
    Location
    Islamabad
    Posts
    99

    Re: Exception When Accessing Process.StartTime, Excep:"Access is Denied"

    Hi there,

    Thanx mariocatch for your reply. I have added my user account to group "Performance Log Users" but no benefit of doing that.

    I m having same exception.

    best regards,
    Cyber Friend

  4. #4
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: Exception When Accessing Process.StartTime, Excep:"Access is Denied"

    Are you getting that exception for every process ?? There are few peocesses such as "System" which deny access to everyone and you should not bother about it.
    Regards,
    Ramkrishna Pawar

  5. #5
    Join Date
    May 2006
    Location
    Islamabad
    Posts
    99

    Re: Exception When Accessing Process.StartTime, Excep:"Access is Denied"

    Hi there,

    Thanx Krishna for ur time on this thread.

    Yes thats true that i m not getting exception for all processes.

    Here is the list of the processes for which I m getting exception on getting their StartTime or TotalProcessorTime property


    ProcessName: wmiprvse ID: 4740
    ProcessName: svchost ID: 1864
    ProcessName: msdtc ID: 1148
    ProcessName: csrss
    ProcessName: MsDtsSrvr
    ProcessName: wmiprvse
    ProcessName: Idle

    The weird thing is that same code is running successfully on VS2003.

    U can check this code
    Code:
    public static void ListAllProcesses()
    {
          Process[] processes = null;
          string mcName = ".";
          try
          {
    	processes = Process.GetProcesses(mcName);                
    	foreach (Process p in processes)
    	{
                           Console.Write("\nProcessName: " + p.ProcessName);
                           Console.Write("\tID: " + p.Id.ToString());
    	       Console.Write("\tStartTime: " + p.StartTime.ToShortTimeString());
     	       Console.Write("\tCPUTime: " +  p.TotalProcessorTime.Duration().Hours.ToString()+":"+p.TotalProcessorTime.Duration().Minutes.ToString()+":"+p.TotalProcessorTime.Duration().Seconds.ToString());                                                                                
                                                       
    	 }
           }
           catch (Exception ex)
           {
    	MessageBox.Show(ex.Message);                
            }
    }
    best regards,
    Cyber Friend

  6. #6
    Join Date
    Aug 1999
    Location
    <Classified>
    Posts
    6,882

    Re: Exception When Accessing Process.StartTime, Excep:"Access is Denied"

    Meaning, the code is working for the processes where your applications has permissions, you will need administrator level access to see most of the process data. Do you have it ?
    Regards,
    Ramkrishna Pawar

  7. #7
    Join Date
    May 2006
    Location
    Islamabad
    Posts
    99

    Re: Exception When Accessing Process.StartTime, Excep:"Access is Denied"

    Hi there,

    Offcourse i m using my Administrator account dear.
    From same account when i run this code using VS2003 the code runs ok, but exception is occuring when i try to run it using VS2005. The problem is that I have to run this code after building in VS2005.

    One more thing

    I tried to use old version of System.dll (v1.1.4322) in my VS2005 project and then run this project . Now the same exception is coming.

    best regards,
    Cyber Friend

  8. #8
    Join Date
    May 2006
    Location
    Islamabad
    Posts
    99

    Angry Re: Exception When Accessing Process.StartTime, Excep:"Access is Denied"

    Hi there,

    One more intersting finding.

    I downloaded the project "CpuUsageManaged" and ran it:

    http://www.codeproject.com/KB/system...scpuusage.aspx


    Process.TotalProcessorTime is being accessed in this project too in VS 2005.
    See Line no: 58 of ProcessCpu.cs in CpuUsageManaged project; I m very perplexed bcoz of this behaviour. I am accessing same property of Process class from System.Diagnostic namespace but getting exception.

    I would be really thankful if anyone can point out my mistake.

    best regards,,
    Cyber Friend

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center