Make Windows refresh icon cache
Asked Answered
M

3

8

I really liked the oxygen appearance of KDE SC 4. I wrote a program to apply these icons to windows. The program is written in NSIS, and is currently nearly fully functional. However, the only way I found to make Windows aware of the icon changes is to kill explorer.exe, delete the icon cache, and respawn explorer.exe. SHChangeNotify with SHCNE_ASSOCCHANGED seems to be unable to make Windows aware of the changes to the Control Panel icon, the My Computer icon, etc. Please suggest a better, less brutal approach to make Windows aware of these changes.

EDIT: I found a program called Icon Tweaker that appears to be able to do this, but it is closed source and so I have no idea how it does this. (IconTweaker: http://www.crystalxp.net/galerie/en.id.83-icontweaker.html)

EDIT: I have this working fine, thanks to Anders' reply (see below). However, I'll just put my working NSIS code here,in case someone else needs it

ReadRegStr $0 HKCU "Control Panel\Desktop\WindowMetrics" "Shell Icon Size"
IntOp $0 $0 + 1
WriteRegStr HKCU "Control Panel\Desktop\WindowMetrics" "Shell Icon Size" $0
SendMessage 0xffff 0x001A 42 0 /TIMEOUT=100000
IntOp $0 $0 - 1
WriteRegStr HKCU "Control Panel\Desktop\WindowMetrics" "Shell Icon Size" $0
SendMessage 0xffff 0x001A 42 0 /TIMEOUT=100000

The $0 register is used to store the Shell Icon Size value of HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics. We then increment the value and do a SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, NULL), followed by a decrement and re-send.

EDIT: As a bonus, this can be used as a hack to get larger (Windows 7 size) desktop icons on Windows XP. Just double the Shell Icon Size value and call SendMessage (don't perform the second change that restores the size)

Meneses answered 14/7, 2010 at 4:1 Comment(2)
I have a similar problem in a C# program. Did you get this working?Fordham
Yes. The code I posted above (NSIS code) did the trick.Meneses
F
7

SystemParametersInfo() has a parameter called SPI_SETICONS that "Reloads the system icons" according to MSDN. I have never tried to use SPI_SETICONS so I don't know if it works, if you wanted to test you would use something like

System::Call 'user32::SystemParametersInfo(i 0x0058,i0,i0,i2)i' ;SPI_SETICONS

If it turns out that this is not enough, you can bring out the big undocumented hammer:

  1. Read REG_SZ value named "Shell Icon Size" in HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics (If the value is not there, either abort or use GetSystemMetrics(SM_CXICON))
  2. Subtract 1 from the number you got from step one
  3. Write the modified entry back to the registry
  4. Call SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, NULL)
  5. Write the number you got from step one entry back to the registry
  6. Call SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, NULL)

Note that this could re-arrange the desktop icons even if "Auto Arrange" is off and possibly other things that might annoy the user!

Filomenafiloplume answered 14/7, 2010 at 8:36 Comment(1)
@Sudarshan S: ReadRegStr,IntOp,WriteRegStr,SendMessage 0xffff 0x001A 42 0 /TIMEOUT=100000 are all built-in commands, System::Call 'user32::GetSystemMetrics(i 11)i.r0' will give you SM_CXICON size in $0Filomenafiloplume
S
9

You can just run the following command line:

c:\Windows\System32\ie4uinit.exe -ClearIconCache

That command line will delete your cache icons without need to restart explorer

Southbound answered 18/12, 2013 at 13:52 Comment(1)
Not sure what this does, but it doesn't clear the icon cache.Drugge
F
7

SystemParametersInfo() has a parameter called SPI_SETICONS that "Reloads the system icons" according to MSDN. I have never tried to use SPI_SETICONS so I don't know if it works, if you wanted to test you would use something like

System::Call 'user32::SystemParametersInfo(i 0x0058,i0,i0,i2)i' ;SPI_SETICONS

If it turns out that this is not enough, you can bring out the big undocumented hammer:

  1. Read REG_SZ value named "Shell Icon Size" in HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics (If the value is not there, either abort or use GetSystemMetrics(SM_CXICON))
  2. Subtract 1 from the number you got from step one
  3. Write the modified entry back to the registry
  4. Call SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, NULL)
  5. Write the number you got from step one entry back to the registry
  6. Call SendMessageTimeout(HWND_BROADCAST, WM_SETTINGCHANGE, SPI_SETNONCLIENTMETRICS, 0, SMTO_ABORTIFHUNG, 100000, NULL)

Note that this could re-arrange the desktop icons even if "Auto Arrange" is off and possibly other things that might annoy the user!

Filomenafiloplume answered 14/7, 2010 at 8:36 Comment(1)
@Sudarshan S: ReadRegStr,IntOp,WriteRegStr,SendMessage 0xffff 0x001A 42 0 /TIMEOUT=100000 are all built-in commands, System::Call 'user32::GetSystemMetrics(i 11)i.r0' will give you SM_CXICON size in $0Filomenafiloplume
C
0

The easy way to refresh your icons is to use Windows Disk Cleanup. I'd suggest most users start with this method - it is quick, easy, and non-scary for beginners.

  • Click your Start menu and type DISK CLEANUP
  • Choose the drive you want to clean (most likely the default C: drive)
  • Check Thumbnails in the list of 'Files to delete'
  • Click OK

Once Windows has finished removing the cached thumbnails, it will just rebuild them when you re-visit a folder. This process is fast and there's no harm done to your system at all by doing this.

Hope this helps!

Constancy answered 6/6, 2022 at 0:54 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.