T. *_*ter 6 c# windows windows-explorer process
我有一个经常使用启动explorer.exe的应用程序。我想重新使用现有的/已经打开的资源管理器窗口,而不是每次启动该过程时都创建一个新的资源管理器窗口。
这是我的代码:
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo
{
UseShellExecute = true,
FileName = "Explorer.exe",
Arguments = myDirectoryPath
};
System.Diagnostics.Process.Start(info);
Run Code Online (Sandbox Code Playgroud)
我没有看到执行此操作的命令行开关。我尝试的一种方法是简单地杀死任何一个现有的资源管理器进程,并将其替换为新的进程:
var processes = System.Diagnostics.Process.GetProcesses(Environment.MachineName);int kills = 0;
for (int i = 0; i < processes.Length; i++)
{
System.Diagnostics.Process p = processes[i];
if (p.ProcessName == "explorer" && kills < 1)
++kills
p.Kill();
}
Run Code Online (Sandbox Code Playgroud)
但是,这不仅导致杀死1个进程,而且导致彻底杀死资源管理器,甚至任务栏也消失,产生了不良后果。
那么,如何使用现有的Explorer窗口(如果存在)来启动Explorer?