Skip to main content

How to Clear the Icon Cache in Batch Script

Broken or generic white icons on your desktop and in File Explorer are often the result of a corrupted Windows Icon Cache. This cache stores copies of all icons used by the operating system, preventing the need to extract them from every .exe and .dll file each time a folder is opened. When the cache becomes corrupted, icons appear as wrong images, generic white squares, or disappear entirely. Clearing the cache forces Windows to rebuild it from the actual application files.

This guide explains how to safely reset the icon cache, covering both the legacy IconCache.db and the modern iconcache_*.db files used in Windows 10/11.

Understanding the Icon Cache Files

Windows maintains icon caches in two locations:

FileLocationWindows Version
IconCache.db%LocalAppData%\Windows 7/8 (legacy, may still exist on 10/11)
iconcache_*.db%LocalAppData%\Microsoft\Windows\Explorer\Windows 10/11 (multiple files for different icon sizes)

Both locations may contain active cache files on Windows 10/11 systems. A complete reset must clear both.

User-Level Task: No Admin Required

The icon cache files are in your user profile (%LocalAppData%). Clearing them does not require administrator privileges. Each user has their own icon cache.

Common symptoms of icon cache corruption:

  • Desktop shortcuts show generic white squares instead of application icons
  • Taskbar pinned items display the wrong icon
  • File type icons (e.g., .pdf, .docx) show as blank
  • Icons display correctly in some views but not others (e.g., large icons work but small icons don't)
  • After installing/uninstalling software, old or wrong icons persist

Method 1: Complete Icon Cache Reset

This method clears both the legacy and modern icon cache files, with proper Explorer management and verification.

@echo off
setlocal

set "LegacyCache=%LocalAppData%\IconCache.db"
set "ModernCacheDir=%LocalAppData%\Microsoft\Windows\Explorer"

echo ============================================================
echo Windows Icon Cache Repair Tool
echo ============================================================
echo.

:: Count existing cache files
set "FileCount=0"

if exist "%LegacyCache%" set /a "FileCount+=1"

for %%f in ("%ModernCacheDir%\iconcache_*.db") do (
set /a "FileCount+=1"
)

if %FileCount% equ 0 (
echo [INFO] No icon cache files found. Cache is already clean.
echo [INFO] If icons are still broken, try rebooting the computer.
endlocal
exit /b 0
)

echo [INFO] Found %FileCount% icon cache file(s) to clear.
echo.
echo [WARNING] Your taskbar and desktop will temporarily disappear.
echo This is normal, Explorer will restart automatically.
echo Close any open File Explorer windows before proceeding.
echo.

set /p "Confirm=Clear the icon cache? (YES/no): "
if /i not "%Confirm%"=="YES" (
echo [INFO] Cancelled. No changes made.
endlocal
exit /b 0
)

echo.

:: =============================================
:: Step 1: Terminate Explorer
:: =============================================
echo [1/3] Stopping Explorer shell...

taskkill /f /im explorer.exe >nul 2>&1

:: Wait for file handles to release
timeout /t 3 /nobreak >nul

:: Verify Explorer stopped
tasklist /fi "IMAGENAME eq explorer.exe" 2>nul | findstr /i "explorer" >nul
if not errorlevel 1 (
echo [RETRY] Explorer still running. Retrying...
taskkill /f /im explorer.exe >nul 2>&1
timeout /t 3 /nobreak >nul
)

echo [OK] Explorer stopped.

:: =============================================
:: Step 2: Delete icon cache files
:: =============================================
echo [2/3] Deleting icon cache files...

set "Deleted=0"
set "Failed=0"

:: Delete legacy IconCache.db (may be hidden)
if exist "%LegacyCache%" (
attrib -h -s -r "%LegacyCache%" >nul 2>&1
del /f /q "%LegacyCache%" >nul 2>&1
if not exist "%LegacyCache%" (
echo [OK] Deleted: IconCache.db (legacy^)
set /a "Deleted+=1"
) else (
echo [FAIL] Could not delete: IconCache.db >&2
set /a "Failed+=1"
)
)

:: Delete modern iconcache_*.db files
for %%f in ("%ModernCacheDir%\iconcache_*.db") do (
attrib -h -s -r "%%f" >nul 2>&1
del /f /q "%%f" >nul 2>&1
if not exist "%%f" (
echo [OK] Deleted: %%~nxf
set /a "Deleted+=1"
) else (
echo [FAIL] Could not delete: %%~nxf >&2
set /a "Failed+=1"
)
)

echo.
echo Deleted: %Deleted% Failed: %Failed%

:: =============================================
:: Step 3: Restart Explorer
:: =============================================
echo [3/3] Restarting Explorer shell...

start "" explorer.exe

:: Wait and verify restart
timeout /t 2 /nobreak >nul

tasklist /fi "IMAGENAME eq explorer.exe" 2>nul | findstr /i "explorer" >nul
if errorlevel 1 (
echo [WARNING] Explorer may not have restarted. Trying again... >&2
start "" explorer.exe
timeout /t 2 /nobreak >nul
)

echo [OK] Explorer restarted.

echo.

if %Failed% equ 0 (
echo [OK] Icon cache cleared successfully.
echo Windows will rebuild icons as you navigate.
echo Icons may briefly appear as white squares: this is normal.
) else (
echo [WARNING] %Failed% file^(s^) could not be deleted. >&2
echo A reboot may be needed to fully clear the cache. >&2
)

echo.
echo ============================================================

endlocal
exit /b 0

Why attrib -h -s -r before deletion:

The IconCache.db file and some iconcache_*.db files are marked with Hidden (H), System (S), and/or Read-Only (R) attributes. The del command may silently skip files with these attributes. Stripping all three before deletion ensures the files can be removed.

Why start "" explorer.exe:

Without the empty quotes, start explorer.exe may interpret explorer.exe as a window title parameter and open a File Explorer window instead of restarting the shell. The empty quotes explicitly set an empty window title, ensuring explorer.exe is treated as the command.

If Explorer Doesn't Restart

If the script fails between killing Explorer and restarting it, you'll have a blank screen with no taskbar. To recover:

  1. Press Ctrl+Shift+Esc to open Task Manager
  2. Click File → Run new task
  3. Type explorer.exe and press Enter

This restarts the Windows shell immediately.

Method 2: Icon + Thumbnail Combined Reset

Icon and thumbnail corruption often occur together, the same cache infrastructure serves both. Clearing both caches in one operation provides the most thorough fix for all visual issues.

@echo off
setlocal

set "ExplorerCacheDir=%LocalAppData%\Microsoft\Windows\Explorer"
set "LegacyIconCache=%LocalAppData%\IconCache.db"

echo ============================================================
echo Complete Visual Cache Reset (Icons + Thumbnails)
echo ============================================================
echo.
echo [INFO] This clears ALL icon and thumbnail caches.
echo [WARNING] Taskbar and desktop will temporarily disappear.
echo.

set /p "Confirm=Proceed? (YES/no): "
if /i not "%Confirm%"=="YES" (
echo [INFO] Cancelled.
endlocal
exit /b 0
)

:: Stop Explorer
echo.
echo [ACTION] Stopping Explorer...
taskkill /f /im explorer.exe >nul 2>&1
timeout /t 3 /nobreak >nul

:: Clear all cache files
echo [ACTION] Clearing caches...

set "TotalDeleted=0"

:: Legacy icon cache
if exist "%LegacyIconCache%" (
attrib -h -s -r "%LegacyIconCache%" >nul 2>&1
del /f /q "%LegacyIconCache%" 2>nul
set /a "TotalDeleted+=1"
)

:: Modern icon and thumbnail caches
for %%f in (
"%ExplorerCacheDir%\iconcache_*.db"
"%ExplorerCacheDir%\thumbcache_*.db"
) do (
attrib -h -s -r "%%f" >nul 2>&1
del /f /q "%%f" 2>nul
set /a "TotalDeleted+=1"
)

echo [OK] Cleared %TotalDeleted% cache file(s).

:: Restart Explorer
echo [ACTION] Restarting Explorer...
start "" explorer.exe

timeout /t 2 /nobreak >nul

echo.
echo [OK] All visual caches cleared.
echo Icons and thumbnails will regenerate as you browse.
echo The first folder visit will be slower than usual.
echo.
echo ============================================================

endlocal
exit /b 0

When to use combined reset vs. icon-only:

SymptomRecommended Action
Only application icons are wrongMethod 1 (icon cache only)
Only file/folder thumbnails are wrongClear thumbnail cache only
Both icons and thumbnails are wrongMethod 2 (combined reset)
After Windows Update with visual issuesMethod 2 (combined reset)
After installing/uninstalling many appsMethod 1 or 2 depending on symptoms

Method 3: Non-Disruptive Reset (Schedule for Next Login)

For situations where killing Explorer is not acceptable (active work, presentations, remote sessions), schedule the cleanup to run at the next login before Explorer locks the cache files.

@echo off
setlocal

echo [INFO] Scheduling icon cache cleanup for next login...
echo [INFO] No disruption to your current session.
echo.

set "CleanupScript=%TEMP%\clear_icon_cache_login.bat"

:: Create a self-deleting cleanup script
(
echo @echo off
echo :: Clear legacy icon cache
echo attrib -h -s -r "%LocalAppData%\IconCache.db" 2^>nul
echo del /f /q "%LocalAppData%\IconCache.db" 2^>nul
echo :: Clear modern icon cache
echo for %%%%f in ("%LocalAppData%\Microsoft\Windows\Explorer\iconcache_*.db"^) do (
echo attrib -h -s -r "%%%%f" 2^>nul
echo del /f /q "%%%%f" 2^>nul
echo ^)
echo :: Self-delete
echo del "%%~f0"
) > "%CleanupScript%"

:: Register for RunOnce execution at next login
reg add "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce" /v "ClearIconCache" /t REG_SZ /d "\"%CleanupScript%\"" /f >nul 2>&1

if not errorlevel 1 (
echo [OK] Cleanup scheduled for next login.
echo Icons will be rebuilt automatically after your next sign-in.
) else (
echo [ERROR] Could not schedule cleanup. >&2
del "%CleanupScript%" 2>nul
endlocal
exit /b 1
)

endlocal
exit /b 0

How this works:

The RunOnce registry key contains commands that execute once during the login sequence, before Explorer fully initializes and locks the cache files. The cleanup script runs, deletes the cache, and then deletes itself. On the next login after that, the RunOnce entry is gone and the cleanup doesn't repeat.

Combine with Thumbnail Cleanup

Method 3 can be extended to clear both icon and thumbnail caches by adding thumbcache_*.db to the cleanup script. This provides a complete non-disruptive visual reset.

Method 4: Rebuild with ie4uinit (Windows Built-in)

Windows includes a built-in command that forces icon cache recreation without killing Explorer, though it requires a prior cache deletion or doesn't always work in isolation.

@echo off
setlocal

echo [INFO] Forcing icon cache rebuild via ie4uinit...

:: This command is available on Windows 10/11
:: It instructs the shell to re-read all icon associations
ie4uinit.exe -show

echo [OK] Icon rebuild command issued.
echo If icons are still wrong, use Method 1 for a full cache reset.

endlocal
exit /b 0

Limitations of ie4uinit:

  • It does NOT delete the existing cache, it tells Explorer to refresh icons from their source files.
  • If the cache is corrupted, refreshing may reload corrupted data. A full cache deletion (Methods 1–2) is more reliable for corruption issues.
  • It works best for cases where icons are simply outdated (after changing a file association or installing new software), not for corruption.

How to Avoid Common Errors

Wrong Way: Deleting Cache Files Without Stopping Explorer

:: FAILS: Explorer has the cache files locked
del /f /q %LocalAppData%\IconCache.db
:: Result: "Access is denied" or "The process cannot access the file"

Correct Way: Kill Explorer first (Methods 1–2), or schedule deletion before Explorer starts (Method 3).

Wrong Way: Forgetting the Hidden Attribute

:: MAY SILENTLY SKIP - IconCache.db is a hidden file
del /f /q %LocalAppData%\IconCache.db
:: File may appear "deleted" but still exists because del skipped it

Correct Way: Strip the hidden, system, and read-only attributes before deletion:

attrib -h -s -r "%LocalAppData%\IconCache.db"
del /f /q "%LocalAppData%\IconCache.db"

Wrong Way: Clearing Only the Legacy Cache

:: INCOMPLETE: misses the modern iconcache_*.db files
del /f /q %LocalAppData%\IconCache.db
:: On Windows 10/11, most icons are in iconcache_*.db files, not IconCache.db

Correct Way: Clear both the legacy IconCache.db and the modern iconcache_*.db files (Methods 1–2).

Problem: Icons Still Broken After Clearing Cache

If clearing the cache doesn't fix the icons:

  1. Reboot: Some icon data persists in memory. A reboot forces a complete rebuild.
  2. Check the application: The icon may be missing from the application's .exe file itself (corrupted installation).
  3. Rebuild the application shortcut: Delete the shortcut and create a new one from the application's .exe.
  4. Check file association: The file type may not be associated with any program (assoc .ext and ftype).

Problem: Frequent Icon Cache Corruption

If the icon cache corrupts repeatedly:

  • Check disk health: Bad sectors can corrupt any file, including the cache. Run chkdsk C: /f.
  • Check for malware: Some malware corrupts system caches. Run a full antivirus scan.
  • Check third-party shell extensions: Faulty Explorer extensions can corrupt the cache during icon rendering.
  • Disable icon cache compression: Some group policies or optimization tools compress the icon cache, causing corruption.

Best Practices and Rules

1. Always Clear Both Legacy and Modern Caches

Windows 10/11 may use both IconCache.db and iconcache_*.db. Clearing only one leaves the other potentially corrupted.

2. Always Restart Explorer After Clearing

Without restarting Explorer, the cache files can't be created fresh. Always include start "" explorer.exe as the final step.

3. Warn About Temporary Visual Disruption

After clearing, icons may briefly appear as white squares or generic icons for a few seconds as Windows rebuilds from the source files. This is normal and resolves quickly.

4. Combine with Thumbnail Cache for Complete Fix

Icon and thumbnail corruption often have the same root cause. Clearing both (Method 2) is more thorough and saves having to run two separate scripts.

5. Use Non-Disruptive Cleanup for Remote or Automated Scenarios

Method 3's RunOnce approach is ideal for deployment via login scripts, Group Policy, or remote management tools: no user disruption during their active session.

6. Reboot If Cache Clearing Alone Doesn't Work

Some icon data is cached in memory by the shell. A full reboot forces Windows to start fresh and read icons exclusively from the newly rebuilt cache.

Conclusion

Clearing the Windows icon cache resolves the most common visual glitches: wrong icons, missing icons, and generic white squares. By handling both the legacy IconCache.db and modern iconcache_*.db files, stripping hidden attributes before deletion, properly managing the Explorer process, and providing non-disruptive alternatives for scheduled cleanup, you create a reliable icon repair tool that works across all current Windows versions.