0

Is there a way to restart all instances of Windows Explorer? It's useful when explorer starts acting up, eg. high cpu .

4
1
; Ctrl F9 - restarts all windows explorer.
^F9::
    Runwait TASKKILL /F /IM explorer.exe
    Run explorer.exe
return

Runwait will wait for the command to complete before going to the next line. This is required, else Run explorer.exe might run too soon, and get killed as well.

1

I have designed a better one using 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 $_
}

It will open the folders which were open before restarting of explorer and kill not responding processes before explorer restart.

1
  • cool, come useful for those who want to preserve the windows.
    – tinker
    Sep 21 '20 at 3:47
1
; 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% 
}
2
  • cool, come useful for those who want to preserve the windows.
    – tinker
    Sep 21 '20 at 3:48
  • the script is erroring out at last 3 lines, putting double quotes on the "n" fixes it. >>> Loop, parse, list, "`n"
    – tinker
    Sep 3 at 7:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.