在不创建窗口的情况下启动 explorer.exe C# [英] Start explorer.exe without creating a window C#
问题描述
我有一个程序可以重新启动 explorer.exe
这是我杀死 explorer.exe
I have a program that restarts explorer.exe
Here is my code for killing explorer.exe
Process[] process = Process.GetProcessesByName("explorer.exe");
foreach (Process theprocess in process) {
theprocess.Kill();
}
以下代码运行成功并停止explorer.exe
这是我启动 explorer.exe
The following code work successfully and stops explorer.exe
Here is my code for starting explorer.exe
Process.Start("explorer");
这也有效,但它还会创建一个 Windows 资源管理器窗口以及启动 explorer.exe
进程.
This also works, but it also creates a Windows Explorer window as well as starting the explorer.exe
process.
我的问题是,如何在不创建 Windows 资源管理器窗口的情况下启动 explorer.exe
?立即关闭资源管理器窗口也可以视为答案.
My question is, how can I start explorer.exe
without creating a Windows Explorer window?Immediately closing the explorer window could also be considered as an answer.
推荐答案
我不知道如何在不打开窗口的情况下启动资源管理器,但是您可以使用 SHDocVW 中的
枚举资源管理器窗口如此处所述,然后在弹出窗口时关闭该窗口:ShellWindows
界面.dll
I don't know how to start explorer without opening a window, but you can use the ShellWindows
interface from SHDocVW.dll
to enumerate explorer windows as explained here and then close the window as it pops up:
// Kill explorer
Process[] procs = Process.GetProcessesByName("explorer");
foreach (Process p in procs)
{
p.Kill();
}
// Revive explorer
Process.Start("explorer.exe");
// Wait for explorer window to appear
ShellWindows windows;
while ((windows = new SHDocVw.ShellWindows()).Count == 0)
{
Thread.Sleep(50);
}
foreach (InternetExplorer p in windows)
{
// Close explorer window
if(Path.GetFileNameWithoutExtension(p.FullName.ToLower()) == "explorer")
p.Quit();
}
这篇关于在不创建窗口的情况下启动 explorer.exe C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!