Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Win32Exception. Access is denied

Status
Not open for further replies.

jr8rdt

IS-IT--Management
Feb 9, 2006
59
0
0
US
it fails on theprocess.StartTime.
"Win32Exception. Access is denied"
I am administrator. so dont understand why I got the message.

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Process[] processlist = Process.GetProcesses();



foreach(Process theprocess in processlist)
{

Console.WriteLine("{0}: {1}: {2}", theprocess.ProcessName, theprocess.Id, theprocess.StartTime);

}
Console.ReadKey();

}
}
}
 
can you post the full stacktrace (exception.ToString())? this doesn't tell us anything.

how do you know it's failing on StartTime and not ProcessName or Id? for debugging set each value to a variable and see where it throws.
Code:
string name = theprocess.ProcessName;
object id = theprocess.Id;
DateTime started = theprocess.StartTime;
Console.WriteLine("{0} | {1} | {2:F}", name, id, started);

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
it outputs the result I wanted. but at the end it throws the error




explorer: 2656: Tuesday, October 06, 2009 1:48:15 PM
svchost: 960: Tuesday, October 06, 2009 1:45:15 PM
ConsoleApplication1.vshost: 5676: Thursday, October 08, 2009 10:16:22 AM
smax4pnp: 2916: Tuesday, October 06, 2009 1:48:29 PM
RunRM: 3860: Tuesday, October 06, 2009 1:48:38 PM
Error: System.ComponentModel.Win32Exception: Access is denied
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 acces
s, Boolean throwIfExited)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfE
xited)
at System.Diagnostics.Process.GetProcessTimes()
at System.Diagnostics.Process.get_StartTime()
at ConsoleApplication1.Program.Main(String[] args) in c:\c#\ConsoleApplicatio
n1\ConsoleApplication1\Program.cs:line 20







 
chances are it's not at the end, it's failing with the next process. try this.
Code:
Process[] processes = Process.GetProcesses();
Console.WriteLine("Number of Processes: {0}", processes.Length);
for(int i=0; i<processes.Length; i++)
{
   Process p = processes[i];
   try
   {
      Console.WriteLine("{0}: {1}({2}) 3:F}", i, p.ProcessName, p.Id, p.StartTime);
   }
   catch(Win32Exception)
   {
      Console.WriteLine("{0} : could not parse", i);
   }
}
Console.ReadKey();
this will tell you the index of the processes theat fail when accessed.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
You are right. Some of the processes get the error some don't (see below). However when I take out p.StartTime I get all processes without error. so what is special with StartTime and I am Administrator why I can't get the StartTime for some?


13: svchost:960: Tuesday, October 06, 2009 1:45:15 PM
14: smax4pnp:2916: Tuesday, October 06, 2009 1:48:29 PM
15: RunRM:3860: Tuesday, October 06, 2009 1:48:38 PM
System.ComponentModel.Win32Exception: Access is denied
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 acces
s, Boolean throwIfExited)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfE
xited)
at System.Diagnostics.Process.GetProcessTimes()
at System.Diagnostics.Process.get_StartTime()
at ConsoleApplication1.Program.Main(String[] args) in c:\c#\ConsoleApplicatio
n1\ConsoleApplication1\Program.cs:line 19 : could not parse
17: TmListen:3080: Tuesday, October 06, 2009 1:46:06 PM
System.ComponentModel.Win32Exception: Access is denied
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 acces
s, Boolean throwIfExited)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfE
xited)
at System.Diagnostics.Process.GetProcessTimes()
at System.Diagnostics.Process.get_StartTime()
at ConsoleApplication1.Program.Main(String[] args) in c:\c#\ConsoleApplicatio
n1\ConsoleApplication1\Program.cs:line 19 : could not parse
19: OUTLOOK:5508: Tuesday, October 06, 2009 3:53:02 PM
20: svchost:1124: Tuesday, October 06, 2009 1:45:18 PM
21: radconsw:5056: Thursday, October 08, 2009 10:27:29 AM
22: smss:588: Tuesday, October 06, 2009 1:45:08 PM
23: winlogon:676: Tuesday, October 06, 2009 1:45:12 PM
24: dexplore:3068: Wednesday, October 07, 2009 1:10:02 PM
System.ComponentModel.Win32Exception: Access is denied
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 acces
s, Boolean throwIfExited)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfE
xited)
at System.Diagnostics.Process.GetProcessTimes()
at System.Diagnostics.Process.get_StartTime()
at ConsoleApplication1.Program.Main(String[] args) in c:\c#\ConsoleApplicatio
n1\ConsoleApplication1\Program.cs:line 19 : could not parse
26: mstsc:2896: Wednesday, October 07, 2009 9:59:17 AM
27: jqs:1916: Tuesday, October 06, 2009 1:45:50 PM
28: mDNSResponder:1736: Tuesday, October 06, 2009 1:45:50 PM
System.ComponentModel.Win32Exception: Access is denied
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 acces
s, Boolean throwIfExited)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfE
xited)
at System.Diagnostics.Process.GetProcessTimes()
at System.Diagnostics.Process.get_StartTime()
at ConsoleApplication1.Program.Main(String[] args) in c:\c#\ConsoleApplicatio
n1\ConsoleApplication1\Program.cs:line 19 : could not parse
30: dllhost:4976: Tuesday, October 06, 2009 5:46:18 PM
31: TOBDE3:4044: Tuesday, October 06, 2009 1:46:27 PM
32: PccNTMon:3776: Tuesday, October 06, 2009 1:48:30 PM
33: mstsc:4576: Wednesday, October 07, 2009 2:33:14 PM
34: RMC:3328: Tuesday, October 06, 2009 1:48:48 PM
35: mysqld-nt:124: Tuesday, October 06, 2009 1:45:52 PM
36: radexecd:656: Tuesday, October 06, 2009 1:45:52 PM
System.ComponentModel.Win32Exception: Access is denied
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 acces
s, Boolean throwIfExited)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfE
xited)
at System.Diagnostics.Process.GetProcessTimes()
at System.Diagnostics.Process.get_StartTime()
at ConsoleApplication1.Program.Main(String[] args) in c:\c#\ConsoleApplicatio
n1\ConsoleApplication1\Program.cs:line 19 : could not parse
38: lsass:740: Tuesday, October 06, 2009 1:45:13 PM
System.ComponentModel.Win32Exception: Access is denied
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 acces
s, Boolean throwIfExited)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfE
xited)
at System.Diagnostics.Process.GetProcessTimes()
at System.Diagnostics.Process.get_StartTime()
at ConsoleApplication1.Program.Main(String[] args) in c:\c#\ConsoleApplicatio
n1\ConsoleApplication1\Program.cs:line 19 : could not parse
40: lcfep:3496: Tuesday, October 06, 2009 1:48:31 PM
41: ConsoleApplication1.vshost:712: Thursday, October 08, 2009 10:55:31 AM
42: Radstgms:1536: Tuesday, October 06, 2009 1:45:54 PM
43: mstsc:3008: Wednesday, October 07, 2009 10:55:06 AM
44: spoolsv:1440: Tuesday, October 06, 2009 1:45:21 PM
System.ComponentModel.Win32Exception: Access is denied
at System.Diagnostics.ProcessManager.OpenProcess(Int32 processId, Int32 acces
s, Boolean throwIfExited)
at System.Diagnostics.Process.GetProcessHandle(Int32 access, Boolean throwIfE
xited)
at System.Diagnostics.Process.GetProcessTimes()
at System.Diagnostics.Process.get_StartTime()
at ConsoleApplication1.Program.Main(String[] args) in c:\c#\ConsoleApplicatio
n1\ConsoleApplication1\Program.cs:line 19 : could not parse
46: jusched:3400: Tuesday, October 06, 2009 1:48:38 PM
47: services:728: Tuesday, October 06, 2009 1:45:13 PM
48: GoogleToolbarNotifier:3664: Tuesday, October 06, 2009 1:48:39 PM
49: hkcmd:2684: Tuesday, October 06, 2009 1:48:28 PM
50: firefox:4968: Wednesday, October 07, 2009 12:08:08 PM
51: TSVNCache:2860: Tuesday, October 06, 2009 1:48:20 PM
52: cmd:3304: Wednesday, October 07, 2009 2:18:42 PM
 
google is your friend:)

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
faq732-7259
 
I gave up.
if anyone can help. I would appreciate.

jmeckley, do you know how to?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top