用 Excel VBA 重启 explorer.exe

Restart explorer.exe with Excel VBA

我正在尝试添加注册表项以在任务栏已满时合并 Windows。之后我需要关闭 explorer.exe 并重新开始。

使用

可以很容易地终止资源管理器进程
shell "taskkill /f /im explorer.exe"

我无法再次启动它

我试过了

Shell "explorer.exe"

Shell "cmd.exe /c explorer.exe"

这两个都打开一个资源管理器 window 但不使用任务栏启动进程。

可能吗?

This 解决方案是 Google 上的首批结果之一。您是否尝试 运行 在同一个 Sub 中执行此操作?

Sub Rumi()
    Shell ("cmd.exe /c taskkill /f /im explorer.exe")

    Application.Wait Now() + TimeValue("00:00:05")

    Shell "cmd.exe /c explorer.exe"
End Sub

解决了

为了使其在 windows10 中工作,您必须调用 explorer.exe

的完整文件路径

Shell("C:\Windows\explorer.exe")

这会正确打开资源管理器进程以及任务栏和桌面