Refresh IconCache.db programmatically

2019-06-04 05:59发布

问题:

I have a button for firefox.exe pinned. I changed the pinned icon via registry I set the path to a url:

  1. I added firefox.exe folder to HKEY_LOCAL_MACHINE: HKEY_LOCAL_MACHINE\SOFTWARE\Classes\Applications\ and set it's value to C:\Users\myUsername\Downloads\addon.ico
  2. I added firefox.exe folder to HKEY_CURRENT_USER: HKEY_CURRENT_USER\SOFTWARE\Classes\Applications\ and set it's value to C:\Users\myUsername\Downloads\addon.ico

The icon at that path definitely exists.

However even though my icon is pinned for it doesn't take. I'm guessing I have to refresh the IconCache.db can you please recommend a way to do this with win api? Without restarting computer or program or logging off computer please is my hope.

回答1:

Try this:

SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil)

Or you could try this:

SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, 'YourPinnedFileName', nil)