[英]How to rebuild Windows Icon Cache without closing explorer.exe or restarting Windows?
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. 我正在尝试从我的应用程序中自定义文件夹图标,但由于Windows缓存图标和缩略图的方式,我正在努力让更改的文件夹更新它的新图标。
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. 在Windows中,我知道有两种方法可以自定义文件夹图标,最简单的方法是从Windows资源管理器中右键单击该文件夹,然后选择“自定义”选项卡并更改其图标,但这种方法并不好,尽管它需要手动更改文件夹属性。
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/ 我从我的程序中做的第二种方法是创建一个
desktop.ini
文件并将其放在需要更改图标的文件夹中, desktop.ini
文档可以在这里找到: http://hwiegman.home.xs4all。 nl / desktopini.html和一篇文章: 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: 如下所示,虽然您可以从文件夹属性中看到图标已更改,但Windows中的文件夹图标未更新,只是Windows未显示更新的文件夹图标:
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. 我完全了解Windows缓存图标和缩略图,我已经搜索并阅读了几个关于如何重建图标缓存的页面,从而让Windows显示新更改的图标而不是缓存的图标,但是我无法将其转换为从我的应用程序工作而不重新启动Windows或Explorer.exe进程,这需要在不中断Windows的情况下完成,但是关闭Explorer.exe或者需要重新启动绝对不是一个选项。
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. 有趣的是,当我从前面描述的第一种方式更改文件夹图标时,Windows以某种方式设法刷新并重建图标缓存,因为更改后的文件夹会立即更新以显示新图标,但是我无法看到Windows为实现此目的所做的一些技巧。
A few things I tried unsucessfully, (in no particular order): 我尝试了一些不成功的事情(没有特别的顺序):
ie4uinit.exe -ClearIconCache
ie4uinit.exe -ClearIconCache
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
IconCache.db
file from AppData\\Local
AppData\\Local
删除IconCache.db
文件 "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 "Always show icons, never thumbnails"
资源管理器选项: HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced
,它存储在IconsOnly
值中 HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics
which is stored in the Shell Icon Size
value HKEY_CURRENT_USER\\Control Panel\\Desktop\\WindowMetrics
,它存储在Shell Icon Size
值中 AppData\\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. AppData\\Local\\Microsoft\\Windows\\Explorer
虽然我不确定它们是否有任何帮助,试图删除其中一些似乎不可能,因为它们可能被锁定等。 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. 当直接从Windows资源管理器更改文件夹图标时,使用属性上下文菜单和自定义选项卡,在应用和关闭此对话框时,文件夹图标几乎立即更改,没有关闭explorer.exe或重新启动Windows,更改发生得非常正确远。
How can I achieve this from my Application programmatically the same way Windows Explorer does? 如何以编程方式从我的应用程序以与Windows资源管理器相同的方式实现此目的? Is there a way to find out how Windows Explorer does this?
有没有办法找出Windows资源管理器如何做到这一点?
My Operating System is Windows 10 which could explain why some of the older methods don't work for me. 我的操作系统是Windows 10,它可以解释为什么有些旧方法对我不起作用。
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. 您可以使用
SHChangeNotify
函数执行此操作。
LPCWSTR pszFolder = L"c:\\path\\to\\folder";
SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, pszFolder, NULL);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.