自动关闭 Windows 资源管理器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2387322/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Automatically close windows explorer
提问by harryovers
i am trying to write a program that close explorer then runs another program.
i am getting a problem when trying to close explorer using the following code:
我正在尝试编写一个关闭资源管理器然后运行另一个程序的程序。
尝试使用以下代码关闭资源管理器时遇到问题:
foreach (Process p in Process.GetProcesses())
if (p.MainModule.ModuleName.Contains("explorer"))
p.Kill();
can somebody please let me know why it is doing this and provide a solution
CHEERS
有人可以让我知道它为什么这样做并提供解决方案
CHEERS
p.s. this is not a malicous program, it is going to run a game that doesn't work properly when explorer is in the background
ps 这不是恶意程序,当资源管理器在后台时,它会运行一个无法正常运行的游戏
回答by Nick
The problem is that you can have multiple versions of Explorer running at any one point in time... and you usually need at least one of them. The shell that hosts the Start Menu is actually an instance of Explorer. So if you close all instances of Explorer, you'll also be shutting down the main shell, which is not what you want to do.
问题是您可以在任何一个时间点运行多个版本的 Explorer……而您通常至少需要其中一个。承载开始菜单的外壳实际上是资源管理器的一个实例。因此,如果您关闭 Explorer 的所有实例,您也将关闭主 shell,这不是您想要做的。
However, the fastest way to do get all instances of Explorer and kill them is:
但是,获取资源管理器的所有实例并杀死它们的最快方法是:
foreach (Process p in Process.GetProcessesByName("explorer"))
{
p.Kill();
}
回答by msp
There is a simple undocumented way to exit explorer cleanly, see also question Gracefully Exit Explorer (Programmatically). It is intended for developers working on shell extensions.
有一种简单的未记录的方法可以干净地退出资源管理器,另请参阅问题Gracefully Exit Explorer (Programmatically)。它适用于从事 shell 扩展的开发人员。
The procedure is different for Windows XP and Windows 7:
Windows XP 和 Windows 7 的步骤不同:
Windows XP: Open the shutdown dialog (Start > Shutdown), then cancel the dialog pressing CTRL-SHIFT-ALT-ESC (or hold down CTRL-SHIFT-ALT and press the Button with the mouse).
Windows XP:打开关闭对话框(开始 > 关闭),然后按 CTRL-SHIFT-ALT-ESC 取消对话框(或按住 CTRL-SHIFT-ALT 并用鼠标按下 Button)。
Windows 7: Open the Start menu and then hold CTRL-SHIFT while right-klicking into the empty area of the start menu, see screenshot. A context menu appears, where the second entry is 'Exit Explorer' (without CTRL-SHIFT the context menu has only one entry)
Windows 7:打开“开始”菜单,然后按住 CTRL-SHIFT 的同时右键单击开始菜单的空白区域,请参见屏幕截图。出现一个上下文菜单,其中第二个条目是“退出资源管理器”(没有 CTRL-SHIFT,上下文菜单只有一个条目)
回答by Andrew Rondeau
p.s. this is not a malicous program, it is going to run a game that doesn't work properly when explorer is in the background
ps 这不是恶意程序,当资源管理器在后台时,它会运行一个无法正常运行的游戏
Explorer is a critical Windows component. You should debug why you have problems when Explorer is running, and fix those.
资源管理器是一个关键的 Windows 组件。您应该调试 Explorer 运行时出现问题的原因,并修复这些问题。
Killing Explorer will cause severe problems for your users.
杀死 Explorer 会给您的用户带来严重的问题。