即使具有管理员权限,Process.kill() 在 Windows 7 32 位中也会被拒绝
大家好。
我遇到了一个奇怪的问题。我的应用程序有一个简单的方法,如果 IE 进入无响应状态,则会触发此方法并关闭所有 IE 进程,然后应用程序重新启动 IE 的工作。
方法代码:
foreach (System.Diagnostics.Process exe in System.Diagnostics.Process.GetProcesses())
{
if (exe.ProcessName.StartsWith("iexplore"))
exe.Kill();
}
即使使用管理员权限调试我的应用程序,应用程序有时也会成功运行此方法,而有时即使以管理员身份运行,我也会收到错误访问被拒绝
。
我什至编写了自己的清单文件,指定需要使用管理员权限执行此应用程序,我认为我做对了。
清单代码:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="Demo.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
</asmv1:assembly>
以前有人遇到过同样的问题吗?我该如何纠正这个奇怪的问题。
谢谢
Hello every one.
I'm faced with a weird problem. My application has a simple method that in case IE enters a state were it gets unresponsive this method is fired closing all IE process's and then the application restarts its work with IE.
Method code:
foreach (System.Diagnostics.Process exe in System.Diagnostics.Process.GetProcesses())
{
if (exe.ProcessName.StartsWith("iexplore"))
exe.Kill();
}
Even debugging my application with Administrator privileges the application sometimes runs this method successfully and some other times i get the error Access Denied
even running as Administrator.
I even coded my own manifest file specifying the need for this application to be executed with Administrator rights, which i think i got it right.
Manifest Code:
<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly manifestVersion="1.0" xmlns="urn:schemas-microsoft-com:asm.v1" xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" xmlns:asmv2="urn:schemas-microsoft-com:asm.v2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<assemblyIdentity version="1.0.0.0" name="Demo.app"/>
<trustInfo xmlns="urn:schemas-microsoft-com:asm.v2">
<security>
<requestedPrivileges xmlns="urn:schemas-microsoft-com:asm.v3">
<requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
</requestedPrivileges>
</security>
</trustInfo>
<compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
<application>
</application>
</compatibility>
</asmv1:assembly>
Anyone had this same issue before? How can i correct this weird problem.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
鉴于您声称在尝试调用此方法时您始终拥有管理权限,以下内容将解释为什么您会遇到间歇性问题:
System.Diagnostics.Process.Kill:
如果您在 Process-Explorer 中的某个条目上快速点击“删除”+“确定”两次,您就会知道我在说什么。
Given that you say you always possess administrative privileges when you attempt to call this method, the following would explain why you have intermittent issues:
System.Diagnostics.Process.Kill:
If you've quickly hit 'delete' + 'OK' twice, on an entry in Process-Explorer, you'll know what I'm talking about.
您是否将代码包装在 try/catch 块中以查看是否引发异常?如果没有,请尝试
Did you wrap your code in a try/catch block to see if an exception was thrown? If not, try
这是 Internet Explorer 的一个怪癖,它会为一个会话启动多个进程。杀死其中一个可以导致他们全部退出。您可能会看到“进程已退出”异常。这样做:
It is a quirk of Internet Explorer, it starts multiple processes for one session. Killing one of them can cause all of them to exit. You probably see the "process has exited" exception. Do it like this instead:
你不应该使用“foreach”来杀死它,并且在两次杀死之间,你需要延迟才能完全杀死进程
you shouldn't use "foreach" to kill it, and between two kill, you need delay for the process to be killed completely