I have a problem of killing an exe with specific location that runs as administrator. Here is the code i use:
const string PROCESSNAME = "test";
string targetProcessPath = @Path.Combine(myFolder, "test.exe");
Process[] collectionOfProcess = Process.GetProcessesByName(PROCESSNAME);
if (collectionOfProcess.Length >= 1)
{
Process process = collectionOfProcess[0];
string processPath = process.MainModule.FileName;
if (processPath == targetProcessPath)
process.Kill();
}
The problem is it works fine when i run test.exe normally but "access denied" when i run it as administrator. I have also tried to run my program as administrator but it still throws the "access denied" exception. Any help on how to achieve that?