I am trying to customise a folder icon from within my Application but due to the way Windows caches icons and thumbnails I am struggling to get the changed folder to update it's new icon.
In Windows there are two ways that I know of to customise a folders icon, the simplest way is to right click the folder from Windows Explorer, Properties and then select the Customize tab and change its icon, this method is no good though as it requires manually changing the folder properties.
The second way which I am doing from my program is to create a desktop.ini
file and place it inside the folder that requires the icon changing, documentation on desktop.ini
can be found here: http://hwiegman.home.xs4all.nl/desktopini.html and an article here: http://helpdeskgeek.com/how-to/customize-folder-icons-desktop-ini/
As shown below though, the folder icon in Windows is not updated although you can see from the folder properties that the icon has changed, just Windows is not showing the updated folder icon:
I am fully aware of Windows caching icons and thumbnails, I have searched and read several pages on ways to supposedly rebuild the icon cache and thus get Windows to display the newly changed icon and not the cached one, however I am unable to get this to work from my Application without restarting Windows or the Explorer.exe process, this needs to be done without interrupting Windows though so closing Explorer.exe or requiring a restart is absolutely not an option.
Interestingly though, when changing a folder icon from the first way I described earlier, Windows somehow manages to flush and rebuild the icon cache as the changed folder is promptly updated to show the new icon, however I cannot see what tricks Windows does to achieve this.
A few things I tried unsucessfully, (in no particular order):
ie4uinit.exe -ClearIconCache
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
IconCache.db
file from AppData\Local
"Always show icons, never thumbnails"
Explorer option from the registry, located here: HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced
which is stored in the IconsOnly
value HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics
which is stored in the Shell Icon Size
valueAppData\Local\Microsoft\Windows\Explorer
although I am not sure if they are of any help, attempting to delete some of them does not seem possible as they may be locked etc.Have also tried performing some of the above in combination with no luck.
When changing a folder icon directly from Windows Explorer, using the properties context menu and customize tab, when applying and closing this dialog the folder icon is changed almost immediately, there is no closing explorer.exe or restarting Windows, the change happens very much right away.
How can I achieve this from my Application programmatically the same way Windows Explorer does? Is there a way to find out how Windows Explorer does this?
My Operating System is Windows 10 which could explain why some of the older methods don't work for me.
In the following content, you can learn how to perform icon cache rebuild on Windows 11/10 with Command Prompt. Step 1: Press Win + S to open the Windows Search utility. Then search for Command Prompt and run it as administrator. Step 2: In Command Prompt, input the commands below one by one and press Enter after each:
Press Windows key+X and click on “Run” from the menu that pops up near the taskbar. Enter the following command on a Windows 10 PC to instantly clear icon cache. If you have any other version of Windows installed, type the following command to clear icon cache.
Open Start and do a search for Command Prompt. Right-click the result and select Run as administrator. Type the following command to navigate to the icon cache database location and press Enter: Type the following command to verify the icon cache database files are at the location and press Enter:
These cache files contain small thumbnails for different files on your computer and Windows Explorer loads the thumbnails from these files as opposed to generating thumbnails for each image again and again when you open a folder in it.
I don't think this is anything to do with icon caching; you just need to inform Explorer that the folder's icon has changed. You can do this using the SHChangeNotify
function.
LPCWSTR pszFolder = L"c:\\path\\to\\folder";
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, pszFolder, NULL);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With