-
March 5th, 2008, 02:35 AM
#1
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
-
March 6th, 2008, 10:24 PM
#2
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.
-
March 7th, 2008, 06:20 AM
#3
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
-
March 7th, 2008, 06:45 AM
#4
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
-
March 7th, 2008, 08:12 AM
#5
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
-
March 7th, 2008, 08:20 AM
#6
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
-
March 7th, 2008, 09:00 AM
#7
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
-
March 7th, 2008, 10:42 AM
#8
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|