[Batch] Restart explorer script #597
Replies: 2 comments
-
I made a better version of the script that shows a dialog asking to restart Explorer. It's a one-liner, so no script file is needed. But you need Powershell and VBScript (they're enabled by default in Windows 8+). Just paste the snippet into
Explanation:
I have edited this comment a few times to improve comments and remove WorkingDirectory (it doesn't work on some installations). |
Beta Was this translation helpful? Give feedback.
-
Here's a PowerShell code that restarts
UPDATE: v2
Functionfunction RestartExplorer
{
$openTabs = @()
(New-Object -ComObject Shell.Application).Windows() | ForEach-Object { $openTabs += $_.Document.Folder.Self.Path }
Stop-Process -ProcessName explorer -Force
Start-Sleep 2
$openTabs | ForEach-Object { Start-Process explorer.exe $_ -WindowStyle Minimized }
} One-liner$t=@();(New-Object -co Shell.Application).Windows()|%{$t+=$_.Document.Folder.Self.Path};kill -proc explorer -for;sleep 2;$t|%{start explorer $_ -win min} In scripts.yaml- Name: Restart explorer.exe and save opened tabs
Command: powershell
ArgsLight: [-c, "$t=@();(New-Object -co Shell.Application).Windows()|%{$t+=$_.Document.Folder.Self.Path};kill -proc explorer -for;sleep 2;$t|%{start explorer $_ -win min}"]
ArgsDark: [-c, "$t=@();(New-Object -co Shell.Application).Windows()|%{$t+=$_.Document.Folder.Self.Path};kill -proc explorer -for;sleep 2;$t|%{start explorer $_ -win min}"]
AllowedSources: [Any] Old versionsv1: Function:function RestartExplorer
{
$openTabs = (New-Object -ComObject 'Shell.Application').Windows() | ForEach-Object { ($_.Document.Folder.Self.Path) }
taskkill.exe /f /im explorer.exe
Start-Sleep 1
Start-Process explorer.exe
$openTabs | ForEach-Object { Start-Process explorer.exe $_ -WindowStyle Minimized }
} One-liner:$t=(New-Object -ComObject 'Shell.Application').Windows()|%{($_.Document.Folder.Self.Path)};taskkill.exe /f /im explorer.exe;sleep 1;start explorer.exe;$t|%{start explorer.exe $_ -windowstyle minimized} As script in scripts.yaml- Name: Restart explorer.exe and save opened tabs
Command: powershell
ArgsLight: [-c, "$t=(New-Object -ComObject 'Shell.Application').Windows()|%{($_.Document.Folder.Self.Path)};taskkill.exe /f /im explorer.exe;sleep 1;start explorer.exe;$t|%{start explorer.exe $_ -windowstyle minimized}"]
ArgsDark: [-c, "$t=(New-Object -ComObject 'Shell.Application').Windows()|%{($_.Document.Folder.Self.Path)};taskkill.exe /f /im explorer.exe;sleep 1;start explorer.exe;$t|%{start explorer.exe $_ -windowstyle minimized}"]
AllowedSources: [Any] |
Beta Was this translation helpful? Give feedback.
-
Info
Please check out the responses below for more fine grained control of the explorer restart procecure.
What is this?
With this custom script you can automatically restart explorer when the theme switches.
This is intrusive and I don't recommend doing this, but here's the script nonetheless.
ALL of your explorer windows will close and will not re-open automatically.
Active copy processes may abort.
Script
Save as
restart_explorer.bat
or whatever you prefer.How should I set this up in the ADM scripts file?
Example ADM scripts configuration:
Change the
{YOUR_PATH_TO_THE_SCRIPT}
placeholder to the location where your script resides at.That's it.
You can find more info on how to configure ADM scripts here:
https://github.com/AutoDarkMode/Windows-Auto-Night-Mode/wiki/How-to-add-custom-scripts
Disclaimer
Beta Was this translation helpful? Give feedback.
All reactions