Process.Kill()访问被拒绝 [英] Process.Kill() Access Denied
问题描述
当我运行以下代码时,将为访问被拒绝"引发Win32Exception.我无法通过搜索找到任何解决方案.我该如何解决?
When I run the following code, a Win32Exception is thrown for Access Denied. I cannot find any solutions via search. How do I fix this?
foreach (ListViewItem list in showprocesses.SelectedItems)
{
Process p = System.Diagnostics.Process.GetProcessById(Convert.ToInt32(list.Tag));
if (p != null)
p.Kill();
}
推荐答案
如果没有必要的权限,通常会收到此错误.您必须是管理员,并且在win vista及更高版本中,以提升模式运行您的应用程序/进程.此外,有些进程即使是管理员,您也无法杀死它们,某些进程被认为对系统至关重要,等等,并且您可能需要以 system 身份运行,然后还有一些甚至是系统无法杀毒(例如杀毒软件或实际病毒),因为他们不希望您杀死他们的进程
You will generally get this error if you do not have the necessary permissions. You must be an administrator, and in win vista and above, run your app/process in elevated mode. Furthermore, there are certain processes that even as admin you won't be able to kill, some deemed system critical, etc, and you may need to run as system, and then there are those that even system can't kill, like antivirus, or an actual virus, because they don't want you killing their process
另一种可能性是,如果该进程已经终止,那么也会抛出该异常,请参见
Another possibility is that if the process is already terminating, it will also throw that exception, see MSDN
这篇关于Process.Kill()访问被拒绝的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!