; Get a list of all opened explorer windows:
If WinExist("ahk_class CabinetWClass") ; explorer
{
list := ""
; https://autohotkey.com/boards/viewtopic.php?p=28751#p28751
for window in ComObjCreate("Shell.Application").Windows
{
explorer_path := ""
try explorer_path := window.Document.Folder.Self.Path
list .= explorer_path ? explorer_path "`n" : ""
}
list := trim(list, "`n")
}
; MsgBox, %list%
RunWait, %comspec% /c taskkill /f /im explorer.exe ,,hide
Process, WaitClose, explorer.exe
; We can now restart the Explorer.exe Process:
Run, explorer.exe
; open all explorer windows we had open previously:
If (list != "")
{
Process, wait, explorer.exe
Loop, parse, list, `n
Run %A_LoopField%
}
Runwait 将等待命令完成,然后再转到下一行。这是必需的,否则 Run explorer.exe 可能会运行得太快,并且也会被杀死。
我使用powershell设计了一个更好的:
它将打开在资源管理器重新启动之前打开的文件夹,并在资源管理器重新启动之前杀死没有响应的进程。