Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Exception When Accessing Process.StartTime, Exc:"Access is Denied"

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

Scheduled Pinned Locked Moved C#
csharpdebugging
4 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Cyber Friend
    wrote on last edited by
    #1

    Hi there, I have to get processes info for a system but I m having an Exception "Access is denied" in this 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,

    C G 2 Replies Last reply
    0
    • C Cyber Friend

      Hi there, I have to get processes info for a system but I m having an Exception "Access is denied" in this 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,

      C Offline
      C Offline
      Christian Graus
      wrote on last edited by
      #2

      What process are you trying to get to ? I guess access is denied.

      Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

      C 1 Reply Last reply
      0
      • C Christian Graus

        What process are you trying to get to ? I guess access is denied.

        Christian Graus - Microsoft MVP - C++ "also I don't think "TranslateOneToTwoBillion OneHundredAndFortySevenMillion FourHundredAndEightyThreeThousand SixHundredAndFortySeven()" is a very good choice for a function name" - SpacixOne ( offering help to someone who really needed it ) ( spaces added for the benefit of people running at < 1280x1024 )

        C Offline
        C Offline
        Cyber Friend
        wrote on last edited by
        #3

        Hi there, Thanx for reply Graus. This process is causing the exception. Name: msdtc MS DTCconsole program ImagePath: C:\WINDOWS\system32\msdtc.exe I m running this code in Vs 2005, While same code is running succesfully in VS 2003. I can't understand this weird behaviour. Here is complete code of my method, u can test it on VS03. 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

        1 Reply Last reply
        0
        • C Cyber Friend

          Hi there, I have to get processes info for a system but I m having an Exception "Access is denied" in this 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,

          G Offline
          G Offline
          Giorgi Dalakishvili
          wrote on last edited by
          #4

          If you are getting the error on Vista or Windows 7 it can be caused by UAC. See this blog post for a workaround: Bugs in System.Diagnostics.Process Class

          Giorgi Dalakishvili #region signature My Articles Browsing xkcd in a windows 7 way[^] #endregion

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups