有没有办法重新启动 Windows 资源管理器的所有实例?当资源管理器开始出现故障(例如 CPU 占用高)时,这种方法很有用。
答案1
; Ctrl F9 - restarts all windows explorer.
^F9::
Runwait TASKKILL /F /IM explorer.exe
Run explorer.exe
return
Runwait 将等待命令完成后再转到下一行。这是必需的,否则 Run explorer.exe 可能会运行得太早,并会被终止。
答案2
我使用 powershell 设计了一个更好的:
$open_folders = @()
$shell = New-Object -ComObject Shell.Application
$shell.Windows() | Foreach {
$open_folders += $_.LocationURL
}
taskkill /f /fi "status eq not responding" >$null
Stop-Process -Name explorer -Force
explorer.exe
$open_folders | foreach {
Invoke-Item $_
}
它将打开在资源管理器重新启动之前打开的文件夹,并在资源管理器重新启动之前终止没有响应的进程。
答案3
; 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%
}