如何重新使用现有/已经打开的 Windows 资源管理器窗口来启动资源管理器

编程入门 行业动态 更新时间:2024-10-27 22:25:16
本文介绍了如何重新使用现有/已经打开的 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 资源管理器窗口来启动资源管理器

本文发布于:2023-11-03 19:52:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1555937.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:资源管理器   窗口   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!