Tip 13 : Kill a process using C#, from local to remote

Posted by StanleyGu on ASP.net Weblogs See other posts from ASP.net Weblogs or by StanleyGu
Published on Thu, 01 Apr 2010 00:29:00 GMT Indexed on 2010/04/01 1:33 UTC
Read the original article Hit count: 475

Filed under:
|

1. My first choice is always to try System.Diagnostics to kill a process

2. The first choice works very well in killing local processes. I thought the first choice should work for killing remote process too because process.kill() method is overloaded with second argument of machine name. I pass process name plus remote machine name and call the process.kill() method

3. Unfortunately, it gives me error message of "Feature is not supported for remote machines.". Apparently, you can query but not kill a remote process using Process class in System.Diagnostics. The MSDN library document explicitly states that about Process class: Provides access to local and remote processes and enables you to start and stop local system processes.

4. I try my second choice: using System.Management to kill a process running on a remote machine. Make sure add references to System.Management.dll and System.Management.Instrumentation.dll

5. The second choice works very well in killing a remote process. Just need to make sure the account running your program must be configured to have permission to kill a process running on the remote machine.

 

© ASP.net Weblogs or respective owner

Related posts about .NET

Related posts about c#