Danny Beckett
Danny Beckett

Reputation: 20748

What permissions are needed for Process.Kill()?

Am I right in thinking that if a program is run as a user, and the program tries to kill another process started by the same user, this will succeed? And that the user would need to be in the Administrators group to kill any other process (including SYSTEM etc)?

Am I missing anything? Am I wrong/right?

Upvotes: 2

Views: 4268

Answers (1)

chridam
chridam

Reputation: 103365

These articles Permissions for Process.Kill() and Tip 13 : Kill a process using C#, from local to remote I'm sure will aid in testing your assumptions.

** EDIT **

The salient information in those articles is as follows (in case the links are down):

using System.Management;
using System.Management.Instrumentation;

ManagementScope scope = new ManagementScope("\\\\RemoteMachineName\\root\\cimv2");
scope.Connect();

ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process WHERE Name='ProcessName'");
ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);

ManagementObjectCollection objectCollection = searcher.Get();
foreach(ManagementObject managementObject in objectCollection)
{
   managementObject.InvokeMethod("Terminate", null);
}

Upvotes: 3

Related Questions