我需要终止 Windows 资源管理器的进程 (explorer.exe),因为
可以说我使用本机 NT 方法 TerminateProcess
它可以工作,但问题是资源管理器再次启动,无论如何,可能 Windows 正在这样做。当我用 Windows 任务管理器杀死 explorer.exe 时,它不会回来,它仍然被杀死。
我想通过我的应用程序执行任务管理器正在执行的任何操作。
编辑:
感谢@sblom,我解决了这个问题,在注册表中进行快速调整就解决了这个问题。虽然这是一个聪明的黑客,但显然taskmnager有一个更干净的方法来做到这一点,也就是说,我现在决定采用@sblom的方式。
I need to kill windows explorer's process (explorer.exe), for that
lets say i use a native NT method TerminateProcess
It works but the problem is that the explorer starts again, may be windows is doing that, anyway. When i kill explorer.exe with windows task manager, it doesn't come back, its stays killed.
I want to do whatever taskmanager is doing through my application.
Edit:
Thanks to @sblom i solved it, a quick tweak in the registry did the trick. Although its a clever hack, apparently taskmnager has a cleaner way of doing that, that said, i've decided to go with @sblom's way for now.
发布评论
评论(5)
来自 Technet:
您可以设置注册表项
HKLM\Software \Microsoft\Windows NT\CurrentVersion\Winlogon\AutoRestartShell
为 0,将不再自动重启。From Technet:
You can set the registry key
HKLM\Software\Microsoft\Windows NT\CurrentVersion\Winlogon\AutoRestartShell
to 0, and it will no longer auto-restart.“真正的”解决方案。 (完整的程序。经过测试可在 Windows 7 上运行。)
The "real" solution. (Complete program. Tested to work on Windows 7.)
这是此问题的另一个解决方案 - 相反 api 调用它使用 Windows 附带的外部工具(至少是 Win 7 Professional):
我知道 Win32Exception 可能不是最好的异常,但此方法的行为或多或少类似于 Kill - 除了例外它实际上杀死了 Windows 资源管理器。
我已经将它添加为扩展方法,因此您可以直接在 Process 对象上使用它:
您必须首先确保 taskkill 工具在生产环境中可用(似乎在 Windows 上已经有一段时间了: https://web.archive.org/web/20171016213040/http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskkill.mspx?mfr =真)。
编辑: 原始链接已失效,已替换为 Internet Archive Wayback Machine 的缓存。 Windows 2012/2016 的更新文档可在以下位置找到: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/taskkill
Here's another solution to this problem - instead api calls it uses an external tool shipped with windows (at least Win 7 Professional):
I know that Win32Exception may not be the best Exception, but this method acts more or less like Kill - with the exception that it actually kills windows explorer.
I've added it as an extension method, so you can use it directly on Process object:
You must first ensure that the taskkill tool is available on production environment (it seems that it's been for a while with windows: https://web.archive.org/web/20171016213040/http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/taskkill.mspx?mfr=true).
EDIT: Original link dead, replaced with cache from Internet Archive Wayback Machine. Updated documentation for Windows 2012/2016 can be found at: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/taskkill
您可能需要做的是不使用 TerminateProcess,而是向资源管理器窗口和主线程发布 WM_QUIT 消息。这有点复杂,但我发现这个页面有一些示例代码可能会帮助您:
http:// /www.replicator.org/node/100
Windows 将在 TerminateProcess 之后自动重新启动 explorer.exe,以便在崩溃终止的情况下重新启动。
What you probably need to do is instead of using TerminateProcess, post a WM_QUIT message to the explorer windows and main thread. It's a bit involved, but I found this page which has some example code that might help you along:
http://www.replicator.org/node/100
Windows will automatically restart explorer.exe after a TerminateProcess so that it restarts in the case of a crash termination.
我进行了一些研究,结果如下:
因此,您应该更改相关的
RegistryKey
:要更改注册表项,程序应以管理员身份运行:
如果 UAC 已关闭,我会引导您查看此答案。
exe
中嵌入清单文件,这将导致 Windows 7 始终以管理员身份运行该程序,如 回答。reg
命令与此 [Microsoft Windows 文档] 结合使用。6。设置 -重新启动资源管理器- 关闭后:此代码可以关闭
explorer
:I have some researches and these are reslts:
So you should change the related
RegistryKey
:For changing a registry key the program should run as administrator:
And if UAC is turned off I direct you to this Answer.
exe
, which will cause Windows Seven to always run the program as an administrator, As explaining in this Answer.reg
command with this [Microsoft Windows Documentation].6.After setting that -restarting explorer- off: This code can close
explorer
: