[英]C# Why can I not programmatically kill a console program started in Task Scheduler?
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.
我有一个UI,可以用来更改控制台程序使用的db中的参数。
I thought it would be great to be able to stop and start this program from the UI and I can do that. 我认为能够从UI停止并启动该程序非常好,我可以做到这一点。
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. 但是,我将控制台程序设置为使用Task Scheduler在工作日之前启动,以防机器应重新启动-至少我知道该程序将在一天开始时运行。
However, I cannot kill it when it has been started by Task Scheduler. 但是,当Task Scheduler启动它时,我无法将其杀死。 Get "Access is denied".
获取“访问被拒绝”。
Why? 为什么? And how can I solve this?
我该如何解决呢?
Try using following method: 尝试使用以下方法:
private void KillProcessByProcessName(string strProcessName)
{
foreach (Process p in System.Diagnostics.Process.GetProcessesByName(strProcessName))
p.Kill();
}
eg: 例如:
private void btnProcessKiller_Click(object sender, EventArgs e)
{
KillProcessByProcessName("winword");
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.