如何重新使用现有/已经打开的 Windows 资源管理器窗口来启动资源管理器 [英] How to re-use existing/already-opened Windows Explorer window to launch Explorer

查看:65
本文介绍了如何重新使用现有/已经打开的 Windows 资源管理器窗口来启动资源管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个经常使用启动 explorer.exe 的应用程序.我想重新使用现有的/已经打开的资源管理器窗口,而不是每次启动该过程时都创建一个新的.

I have an application that makes frequent use of launching explorer.exe. I would like to re-use existing/already-opened explorer windows instead of creating a new one each time I start the process.

这是我的代码的样子:

System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo
{
    UseShellExecute = true,
    FileName = "Explorer.exe",
    Arguments = myDirectoryPath
};
System.Diagnostics.Process.Start(info);

我没有看到用于执行此操作的命令行 开关.我尝试过的一种方法是简单地杀死任何 1 个现有的资源管理器进程并将其替换为新的:

I didn't see a command-line switch to do this. One approach I tried was to simply kill any 1 existing explorer process and replace it with a new one:

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();
}

但这会导致不良影响,不仅杀死 1 个进程,而且完全杀死资源管理器,甚至任务栏也消失了.

But this results in the unwanted effect of not just killing 1 process, but killing explorer completely so that even the taskbar disappears.

那么,您如何使用现有的资源管理器窗口(如果存在)来启动资源管理器?

So, how do you use an existing Explorer window, if one exists, to start Explorer?

推荐答案

IShellWindows COM 界面会给你一个打开的资源管理器窗口列表,你可以获取和设置任何资源管理器窗口的地址,参见此博客条目 用于 C++ 示例.我怀疑 .NET 是否有本机实现,因此您可能需要 PInvoke

The IShellWindows COM interface will give you a list of open explorer windows, you can get and set the address of any explorer window, see this blog entry for a C++ sample. I doubt .NET has a native implementation of this, so you probably need to PInvoke

这篇关于如何重新使用现有/已经打开的 Windows 资源管理器窗口来启动资源管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆