重新启动explorer.exe后重新启动explorer.exe并重新打开相同的窗口? C# [英] Restart explorer.exe and reopening the same windows after restarting explorer.exe? C#

查看:136
本文介绍了重新启动explorer.exe后重新启动explorer.exe并重新打开相同的窗口? C#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello everyone,
This below is the code to restart explorer.exe and it works.

I would like to after the restart explorer.exe, it happens reopen the same windows, 
if they were opened before restart explorer.exe. Thank you.





我的尝试:





What I have tried:

private void restartexplorer()
        {
            const string explorer = "explorer.exe";
            string explorerPath = string.Format("{0}\\{1}", Environment.GetEnvironmentVariable("WINDIR"), explorer);
            foreach (Process process in Process.GetProcesses())
            {
                // In case we get Access Denied
                try
                {
                    if (string.Compare(process.MainModule.FileName, explorerPath, StringComparison.OrdinalIgnoreCase) == 0)
                    {
                        process.Kill();
                    }
                }
                catch
                {
                  //
                }
            }       
        }

推荐答案

显示的代码无法启动资源管理器,您无法重新启动它。所有你能做的就是启动另一个实例。



如果你想为特定目录打开资源管理器,只需将其作为命令行参数传递:

The shown code does not start the Explorer and you can't restart it. All you can do is starting another instance.

If you want to open the Explorer for a specifc directory, just pass that as command line argument:
explorer <directory>



但是可能很难获得之前打开过的文件夹。根据Windows版本,您可以从注册表或 shell获取最近文件夹或项目的列表:最近


这篇关于重新启动explorer.exe后重新启动explorer.exe并重新打开相同的窗口? C#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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