4

I'm using this batch script to change the icons of all the folders and sub-folders to the .ico files that are located in the folders.

However the folder icons do not change in Explorer unless I manually rename desktop.ini file in Explorer to something else and then back to desktop.ini or change the letters to uppercase for example.

I even wrote a batch function to automatically rename the desktop.ini but it doesn't work.

What is the difference between renaming them manually and renaming it from a batch file and how can I make Explorer use the new desktop.ini?

@echo off

for /r %%I in (*.ico) do (
    attrib -r -s "%%~dpI." /S /D 

    if exist %%~dpIdesktop.ini (
        del "%%~dpIdesktop.ini"
    ) 
    >>%%~dpIdesktop.ini echo [.ShellClassInfo]
    >>%%~dpIdesktop.ini echo IconResource="%%~nI%%~xI",0

    attrib -h desktop.ini /S
    attrib +r -s "%%~dpI." /S /D        
)
wOxxOm
  • 65,848
  • 11
  • 132
  • 136
HumansAreDead
  • 69
  • 1
  • 4

2 Answers2

5

Use a shell function that will notify all running Explorer windows to use the updated desktop.ini. This API is exposed in VBScript via Shell.Application.NameSpace("folder\").MoveHere:

@echo off
for /r %%I in (*.ico) do (
    attrib -h -s -r "%temp%\desktop.ini" >nul
    (
        echo [.ShellClassInfo]
        echo IconResource="%%~nxI",0
    )>"%temp%\desktop.ini"
    attrib +h +s "%temp%\desktop.ini"
    (
        echo set shell = CreateObject^("Shell.Application"^)
        echo set folder = shell.NameSpace^("%%~dpI"^)
        echo folder.MoveHere "%temp%\desktop.ini", 4+16+1024
    )>"%temp%\updateIcon.vbs"
    cscript //nologo //b "%temp%\updateIcon.vbs"
)
pause

P.S. I forgot most of VB so whoever remembers it may rewrite the entire code in VBS (embedded).

wOxxOm
  • 65,848
  • 11
  • 132
  • 136
0

I am not a big fan of forcefully killing Explorer.exe but I think this will work in a batch file based on what I saw on a few other websites.

taskkill /fi "imagename eq explorer.exe" /f
CD /d %userprofile%\AppData\Local
DEL IconCache.db /a
START explorer.exe
Gerold Meisinger
  • 4,500
  • 5
  • 26
  • 33
Squashman
  • 13,649
  • 5
  • 27
  • 36