New
#30
I created a version of this that re-opens explorer to the folder or item the context menu was triggered from. So it will restart explorer completely, then launch explorer to where you left off to avoid the need to refind the last place you were working.
If anyone likes this let me know.
You can find my script on my pastebin profile: Add_Restart_Explorer_Context_Menu.reg - Pastebin.com
Last edited by SlyFox1186; 14 May 2021 at 20:43. Reason: re-uploaded the script and it changed the URL
Thanks Denis,
I do already have one that I created in myToolbar
that I use. It is just nice to see the different variations that members come up with to perform the same task.
Mine > Kill and Restart Explorer.
How would one make a right-click context menu entry to restart explorer and re-open previously open windows, using @KeithM's PS script?
Thanks!Code:Shell = New-Object -ComObject shell.application $SavedPaths = ( $Shell.Windows() | select -expand LocationURL ) -ne '' Get-Process explorer | Stop-Process $SavedPaths | ForEach { explorer $_ }
Code:(REG Add "HKCR\Directory\Background\shell\Restart Explorer\Command" /VE /D "PowerShell.exe -ExecutionPolicy Bypass -noexit -file D:\KeithM.ps1" /F)
Copy KeithM's script into this file: D:\KeithM.ps1
I will try it out this evening. Thanks!
- - - Updated - - -
@KeithM, @Matthew Wai
Three problems:
1. When I restart explorer, I get the following PowerShell error message:
2. Regardless of what directory is open, the command defaults to open This PCCode:Shell : The term 'Shell' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the spelling of the name, or if a path was included, verify that the path is correct and try again. At C:\KeithM.ps1:1 char:1 + Shell = New-Object -ComObject shell.application + ~~~~~ + CategoryInfo : ObjectNotFound: (Shell:String) [], CommandNotFoundException + FullyQualifiedErrorId : CommandNotFoundException You cannot call a method on a null-valued expression. At C:\KeithM.ps1:2 char:1 + $SavedPaths = ( $Shell.Windows() | select -expand LocationURL ) -ne ' ... + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (:) [], RuntimeException + FullyQualifiedErrorId : InvokeMethodOnNull
3. The Powershell window persists after the operation.
Any ideas?
Thanks!
In KeithM's script, replace the first line with the following line:
$Shell = New-Object -ComObject shell.application
Note that a dollar sign has been added at the beginning. That will also solve the problem mentioned in your question 3.
@KeithM's script does not work as intended. Something is possibly missing.