gpt4 book ai didi

c# - 如果 Windows 资源管理器在特定路径打开,请不要创建新实例

转载 作者:太空宇宙 更新时间:2023-11-03 23:25:52 25 4
gpt4 key购买 nike

我正在使用以下代码,以便当用户单击按钮时,Windows 资源管理器 的实例会在特定路径打开。但这会导致打开 Explorer 的新实例。

我想更改它,以便如果 Explorer 已在同一路径中打开,则程序不会创建新进程,而是将打开的实例置于最前面。

private void button_Click(object sender, EventArgs e)
{
if (Directory.Exists(myPath))
Process filesFolder = Process.Start("explorer.exe", Conf.FilesLocation);
}

最佳答案

您可以使用“打开”动词,它将在资源管理器中打开目录并重新使用现有的 explorer.exe,如果您将它传递给它已经打开的目录:因此,假设 Conf.FilesLocation 是一个目录:

        var proc = new ProcessStartInfo();
proc.FileName = Conf.FilesLocation;
proc.Verb = "open";
proc.WindowStyle = ProcessWindowStyle.Hidden;
Process.Start(proc );

关于c# - 如果 Windows 资源管理器在特定路径打开,请不要创建新实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33826845/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com