Skip to content

Instantly share code, notes, and snippets.

@kenny-kvibe
Last active May 20, 2023 10:34
Show Gist options
  • Save kenny-kvibe/b4740235bc189e030397a90f62098871 to your computer and use it in GitHub Desktop.
Save kenny-kvibe/b4740235bc189e030397a90f62098871 to your computer and use it in GitHub Desktop.
Restart "explorer.exe" & clean the Icon cache, Thumbnail cache & Recycle bin
@ECHO OFF
SETLOCAL
GOTO :MAIN
:SLEEP Function
"%WINDIR%\System32\timeout.exe" %1 1>NUL 2>&1
GOTO :EOF
REM =============================================================
:MAIN
SET "EXPLORERDATA=%LOCALAPPDATA%\Microsoft\Windows\Explorer"
REM =============================================================
@ECHO ^> Stopping Explorer
"%WINDIR%\System32\taskkill.exe" /F /IM explorer.exe
CALL :SLEEP 1
REM =============================================================
@ECHO.
@ECHO ^> Clearing Explorer Cache
REM =====[ Icon Cache ]==========================================
"%WINDIR%\System32\ie4uinit.exe" -show
CALL :SLEEP 1
"%WINDIR%\System32\attrib.exe" -h %LOCALAPPDATA%\IconCache.db
CALL :SLEEP 1
DEL /F /Q %LOCALAPPDATA%\IconCache.db
CALL :SLEEP 1
DEL /F /Q %EXPLORERDATA%\iconcache*.db
CALL :SLEEP 1
IF EXIST %EXPLORERDATA%\IconCacheToDelete (
DEL /F /Q %EXPLORERDATA%\IconCacheToDelete\*
RMDIR /S /Q %EXPLORERDATA%\IconCacheToDelete
CALL :SLEEP 1
)
REM =====[ Thumbnail Cache ]=====================================
DEL /F /Q %EXPLORERDATA%\thumbcache*.db
CALL :SLEEP 1
IF EXIST %EXPLORERDATA%\ThumbCacheToDelete (
DEL /F /Q %EXPLORERDATA%\ThumbCacheToDelete\*
RMDIR /S /Q %EXPLORERDATA%\ThumbCacheToDelete
CALL :SLEEP 1
)
REM =====[ Recycle Bin ]=========================================
RMDIR /S /Q %SYSTEMDRIVE%\$Recycle.bin
CALL :SLEEP 1
ENDLOCAL
REM =============================================================
@ECHO.
@ECHO ^> Starting Explorer
START %WINDIR%\explorer.exe
CALL :SLEEP 1
REM =============================================================
@ECHO ^> Finished Restarting "explorer.exe" Process!
"%WINDIR%\System32\msg.exe" "%USERNAME%" /time:2.5 /server:localhost "Explorer Restarted!"
CALL :SLEEP 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment