Hello,
I'm using the Process class to get all the current running processes on my
machine and looking for a particular process. If I find the process, I want
to kill it. However, I've recently started recieving and exception "Error
Access is denied" when I try to kill this process. However, I can open up
Task Manager and kill the process. I'm running my program under my user name
so I don't get why I can kill it in Task Manager but my program can't kill
the process. Below is the code I'm utilizing:
for(;;)
{
proc = Process.GetProcessesByName(CProcWatch.PROCNAME);
try
{
foreach (Process pr in proc)
{
if (String.Compare(pr.ProcessName, CProcWatch.PROCNAME, true) ==
0)
pr.Kill();
}
}
catch(Exception e)
{
errlog.Log("CProcWatch", "Error " + e.Message + " occured at: " +
System.DateTime.Now.TimeOfDay.ToString());
}
Thread.Sleep(10000);
proc = null;
}
Can anybody tell me why I should be getting the Access denied Exception?
Any help would be much appreciate. Thanks
Steve