0

I have a console program to run a daily batch. I have a UI that I can use to alter parameters in a db that the console program uses.

I thought it would be great to be able to stop and start this program from the UI and I can do that.

However, I have the console program set to start before the work day using Task Scheduler in case the machine should be rebooted - at least I know the program will be running when the day starts.

However, I cannot kill it when it has been started by Task Scheduler. Get "Access is denied".

Why? And how can I solve this?

Dave Tapson
  • 810
  • 1
  • 9
  • 22

1 Answers1

0

Try using following method:

private void KillProcessByProcessName(string strProcessName)
{
    foreach (Process p in System.Diagnostics.Process.GetProcessesByName(strProcessName))
        p.Kill();
}


e.g:

private void btnProcessKiller_Click(object sender, EventArgs e)
{
    KillProcessByProcessName("winword");
}
Siyavash Hamdi
  • 2,764
  • 2
  • 21
  • 32
  • That is what I am using. Works fine if I manually start the process to be killed, but won't kill the exact same process if I start it using Task Scheduler. – Dave Tapson Apr 21 '16 at 20:38