简体   繁体   English

如何在不关闭explorer.exe或重新启动Windows的情况下重建Windows Icon Cache?

[英]How to rebuild Windows Icon Cache without closing explorer.exe or restarting Windows?

Task 任务

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为实现此目的所做的一些技巧。

Attempts 尝试

A few things I tried unsucessfully, (in no particular order): 我尝试了一些不成功的事情(没有特别的顺序):

  • Executing the following: ie4uinit.exe -ClearIconCache 执行以下命令: ie4uinit.exe -ClearIconCache
  • Running this code in Lazarus: SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil); 在Lazarus中运行此代码: SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);
  • Deleting the IconCache.db file from AppData\\Local AppData\\Local删除IconCache.db文件
  • Toggling the "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值中
  • Changing the icon size from the registry and back, located here: 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值中
  • This link provides an apparent solution in Delphi which I was unable to convert in Lazarus: http://www.aha-soft.com/faq/q18.htm 这个链接在Delphi中提供了一个明显的解决方案,我无法在Lazarus中进行转换: http//www.aha-soft.com/faq/q18.htm
  • I am aware of cached db files here: 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. 我知道缓存的db文件在这里: AppData\\Local\\Microsoft\\Windows\\Explorer虽然我不确定它们是否有任何帮助,试图删除其中一些似乎不可能,因为它们可能被锁定等。
  • Renaming the folder and then rename back to original name. 重命名文件夹,然后重命名回原始名称。
  • Right click an empty space in Windows Explorer and selecting Refresh does not seem to update the folder icon either. 右键单击Windows资源管理器中的空白区域,然后选择“刷新”似乎也不会更新文件夹图标。

Have also tried performing some of the above in combination with no luck. 还尝试过执行上述一些操作,但没有运气。

Question

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM