Process.Kill returns System.ComponentModel.Win32Exception ???

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi All!

I've run into this problem and I would like you to help me please.

Before run my app, I need to iterate through the system process list and kill some processes that consume a lot of CPU, just to free memory:

Dim mProc As Process
For Each mProc In System.Diagnostics.Process.GetProcesses()
If InStr(mProc.ProcessName, "P1", CompareMethod.Text) > 0 Then mProc.Kill()
If InStr(mProc.ProcessName, "P2", CompareMethod.Text) > 0 Then mProc.Kill()
If InStr(mProc.ProcessName, "P3", CompareMethod.Text) > 0 Then mProc.Kill()
Next

The problem is that I got this exception with some of them:

System.ComponentModel.Win32Exception: Access Denied

The same happens when I try to change their PriorityClass property. All I know is that these processes are started by a Windows Service, it seems that they are kind of protected ??? Maybe I can stop the service directly instead (if I know how to do it of course :-) )

Does anybody have any idea to work around this?? I'm new in .NET...

Thanks in advance,
Fernando Paes
 
Fernando,
The proper & polite way to stop a service is to use a
System.ServiceProcess.ServiceController object.

http://msdn.microsoft.com/library/d...ServiceProcessServiceControllerClassTopic.asp

However you still need to have authority to the Service, it sounds like you
may not have authority to the process/service.

Hope this helps
Jay

Fernando Paes said:
Hi All!

I've run into this problem and I would like you to help me please.

Before run my app, I need to iterate through the system process list and
kill some processes that consume a lot of CPU, just to free memory:
Dim mProc As Process
For Each mProc In System.Diagnostics.Process.GetProcesses()
If InStr(mProc.ProcessName, "P1", CompareMethod.Text) > 0 Then mProc.Kill()
If InStr(mProc.ProcessName, "P2", CompareMethod.Text) > 0 Then mProc.Kill()
If InStr(mProc.ProcessName, "P3", CompareMethod.Text) > 0 Then mProc.Kill()
Next

The problem is that I got this exception with some of them:

System.ComponentModel.Win32Exception: Access Denied

The same happens when I try to change their PriorityClass property. All I
know is that these processes are started by a Windows Service, it seems that
they are kind of protected ??? Maybe I can stop the service directly
instead (if I know how to do it of course :-) )
 
Thanks Jay, I'll check this out. But do I need to get autority via code? I can stop the service manually as well as I can finalize the processes in the Task Manager. I conclue that my app can do the same ??? Am I missing something??

ALL: This post was accidentally multiposted, I'd be very grateful if you could please answer in the other topic.

Thanks,
Fernando
 
Back
Top