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

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.

 

Published Wednesday, March 31, 2010 8:29 PM by StanleyGu
Filed under: ,

Comments

# Twitter Trackbacks for Tip 13 : Kill a process using C#, from local to remote - StanleyGu's Blog [asp.net] on Topsy.com

Pingback from  Twitter Trackbacks for                 Tip 13 : Kill a process using C#, from local to remote - StanleyGu's Blog         [asp.net]        on Topsy.com

# Solution 6 : Kill a Non-Clustered Process during Two-Node Cluster Failover

Thursday, April 15, 2010 8:43 PM by StanleyGu's Blog

Using Visual Studio 2008 and C#, I developed a windows service A and deployed it to two nodes of a windows

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

Friday, March 25, 2011 11:58 AM by sam shine

Hi,

I am calling example.exe from asp.net web-page.

Example.exe contains Process.Kill(), but I am not able to kill that process whenever Ill run example.exe from asp.net web page.

I think i need to set some permissions for killing processes.

  What permissions must a user have to be able to succesffuly execute a Process.Kill?

Note : it is working when I double clicking on (example.exe), means its killing some processes

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

Friday, September 02, 2011 9:55 AM by Josh

Good article! Thanks for the help, I've been searching for a while.

Here's a tip to others that may be coming from other sites: in some cases when .NET refers to the "Process Name" they mean the name of the executable without the .exe. This is not the case so don't forget to include the extension in the process name!

# How to kill a process on a seperate machine?

Thursday, January 26, 2012 8:44 AM by Dailycode.Info

How to kill a process on a seperate machine?

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

Thursday, January 26, 2012 8:46 AM by Mark

Thanks for the snippit. I placed a link on my blog.

Works like a charm!

Leave a Comment

(required) 
(required) 
(optional)
(required)