Is there a script out there that rebuilds the icon cache?

Page 1 of 2 12 LastLast

  1. Posts : 129
    Windows 10 Pro 22H2
       #1

    Is there a script out there that rebuilds the icon cache?


    Occasionally I get missing desktop icons where the icon picture is replaced by a white square. The shortcut works fine but the icon is missing it's logo or picture.

    Yeah I know I can go into cmd and enter a number of commands to manually rebuild it (like you see below), but I'm wondering if there is a script out there that can rebuild the icon cache without having to tediously enter command lines manually?

    Something that would contain this...

    taskkill /F /IM explorer.exe
    cd /d %userprofile%\AppData\Local
    attrib -h IconCache.db
    del IconCache.db
    start explorer.exe

    Thanks
      My Computer


  2. Posts : 5,407
    Windows 11 Pro 64-bit
       #2

    Code:
    @echo off
    set iconcache=%localappdata%\IconCache.db
    set iconcache_x=%localappdata%\Microsoft\Windows\Explorer\iconcache*
    
    echo.
    echo The explorer process must be temporarily killed before deleting the IconCache.db file. 
    echo.
    echo Please SAVE ALL OPEN WORK before continuing.
    echo.
    pause
    echo.
    If exist "%iconcache%" goto delete
    echo.
    echo The %localappdata%\IconCache.db file has already been deleted.
    echo. 
    If exist "%iconcache_x%" goto delete
    echo.
    echo The %localappdata%\Microsoft\Windows\Explorer\IconCache_*.db files have already been deleted.
    echo.
    exit /B
    
    
    :delete
    echo.
    echo Attempting to delete IconCache.db files...
    echo.
    ie4uinit.exe -show
    taskkill /IM explorer.exe /F 
    If exist del /A /F /Q "%iconcache%"
    If exist del /A /F /Q "%iconcache_x%"
    start explorer.exe
    echo.
    echo IconCache database files have been successfully deleted.
    goto restart
    
    
    :restart
    echo.
    echo.
    echo You will need to restart the PC to finish rebuilding your icon cache.
    echo.
    CHOICE /C:YN /M "Do you want to restart the PC now?"
    IF ERRORLEVEL 2 goto no
    IF ERRORLEVEL 1 goto yes
    
    :yes
    shutdown /r /f /t 00
    
    :no
    exit /B
      My Computer


  3. Posts : 282
    Windows 10 Pro
       #3

    Take all those commands and enter them line by line like that (just copy/paste) into a text document. Now save the document and rename the .txt extension to a .bat file extension for a batch file. Upon double clicking that batch file all those commands will run. You may need to add some time out commands... 5 Easy Commands to Delay a Batch File in Windows
      My Computer


  4. Posts : 282
    Windows 10 Pro
       #4

    Now add the batch file to Window Task Scheduler and set it at timed intervals...

    This really doesn't solve the underlying issue as to why your icon cache is doing that though. Something is wrong here and the root cause needs to be found. Because you shouldn't need to clear the cache so often.
      My Computer


  5. Posts : 282
    Windows 10 Pro
       #5

    FreeBooter said:
    Code:
    @echo off
    set iconcache=%localappdata%\IconCache.db
    set iconcache_x=%localappdata%\Microsoft\Windows\Explorer\iconcache*
    
    echo.
    echo The explorer process must be temporarily killed before deleting the IconCache.db file. 
    echo.
    echo Please SAVE ALL OPEN WORK before continuing.
    echo.
    pause
    echo.
    If exist "%iconcache%" goto delete
    echo.
    echo The %localappdata%\IconCache.db file has already been deleted.
    echo. 
    If exist "%iconcache_x%" goto delete
    echo.
    echo The %localappdata%\Microsoft\Windows\Explorer\IconCache_*.db files have already been deleted.
    echo.
    exit /B
    
    
    :delete
    echo.
    echo Attempting to delete IconCache.db files...
    echo.
    ie4uinit.exe -show
    taskkill /IM explorer.exe /F 
    If exist del /A /F /Q "%iconcache%"
    If exist del /A /F /Q "%iconcache_x%"
    start explorer.exe
    echo.
    echo IconCache database files have been successfully deleted.
    goto restart
    
    
    :restart
    echo.
    echo.
    echo You will need to restart the PC to finish rebuilding your icon cache.
    echo.
    CHOICE /C:YN /M "Do you want to restart the PC now?"
    IF ERRORLEVEL 2 goto no
    IF ERRORLEVEL 1 goto yes
    
    :yes
    shutdown /r /f /t 00
    
    :no
    exit /B
    Note: This script will power off your computer if you say yes. Really not needed in my opinion...
      My Computer


  6. Posts : 129
    Windows 10 Pro 22H2
    Thread Starter
       #6

    FreeBooter said:
    Code:
    @echo off
    set iconcache=%localappdata%\IconCache.db
    set iconcache_x=%localappdata%\Microsoft\Windows\Explorer\iconcache*
    
    echo.
    echo The explorer process must be temporarily killed before deleting the IconCache.db file. 
    echo.
    echo Please SAVE ALL OPEN WORK before continuing.
    echo.
    pause
    echo.
    If exist "%iconcache%" goto delete
    echo.
    echo The %localappdata%\IconCache.db file has already been deleted.
    echo. 
    If exist "%iconcache_x%" goto delete
    echo.
    echo The %localappdata%\Microsoft\Windows\Explorer\IconCache_*.db files have already been deleted.
    echo.
    exit /B
    
    
    :delete
    echo.
    echo Attempting to delete IconCache.db files...
    echo.
    ie4uinit.exe -show
    taskkill /IM explorer.exe /F 
    If exist del /A /F /Q "%iconcache%"
    If exist del /A /F /Q "%iconcache_x%"
    start explorer.exe
    echo.
    echo IconCache database files have been successfully deleted.
    goto restart
    
    
    :restart
    echo.
    echo.
    echo You will need to restart the PC to finish rebuilding your icon cache.
    echo.
    CHOICE /C:YN /M "Do you want to restart the PC now?"
    IF ERRORLEVEL 2 goto no
    IF ERRORLEVEL 1 goto yes
    
    :yes
    shutdown /r /f /t 00
    
    :no
    exit /B

    Thanks for the quick reply, but when I do it manually, it refreshes the cache in Explorer without having to reboot the machine, which is listed at the end of your script. How would you adjust for that?
      My Computer


  7. Posts : 282
    Windows 10 Pro
       #7

    Something else.

    Go to your Folder Options and chose the option to show hidden files. Now navigate to C:\Users\[your-Windows-username]\AppData\Local and find the hidden IconCache.db. Right click that file and see if it's marked read only. If it is, uncheck that attribute.

    Edit-

    Heck even your avatar is missing its cache! LOL
      My Computer


  8. Posts : 129
    Windows 10 Pro 22H2
    Thread Starter
       #8

    F22 Simpilot said:
    This really doesn't solve the underlying issue as to why your icon cache is doing that though. Something is wrong here and the root cause needs to be found. Because you shouldn't need to clear the cache so often.
    It happens about every three or four months or so. Not too frequent, but if there some kind of underlying cause then I will investigate it further.

    - - - Updated - - -

    F22 Simpilot said:
    Note: This script will power off your computer if you say yes. Really not needed in my opinion...
    How to not power off with your script?
      My Computer


  9. Posts : 18,034
    Win 10 Pro 64-bit v1909 - Build 18363 Custom ISO Install
       #9

    Hello @cheaterslick,

    cheaterslick said:
    How to not power off with your script?
    You could just enter N when the prompt Do you want to restart the PC now? appears.

    Alternatively, do one of the following:

    - Comment out the line shutdown /r /f /t 00. For example :: shutdown /r /f /t 00.
    - Re-write the end of the code with echo. & echo ^>Press ANY key to EXIT . . . & pause >nul & Exit.

    The second one [ preferable ] replacing the Do you want to restart the PC now? section of code.

    I hope this helps.
      My Computer


  10. Posts : 1,204
    11 Home
       #10
      My Computers


 

  Related Discussions
Our Sites
Site Links
About Us
Windows 10 Forums is an independent web site and has not been authorized, sponsored, or otherwise approved by Microsoft Corporation. "Windows 10" and related materials are trademarks of Microsoft Corp.

© Designer Media Ltd
All times are GMT -5. The time now is 12:53.
Find Us




Windows 10 Forums