如何在不关闭 explorer.exe 或重新启动 Windows 的情况下重建 Windows 图标缓存?

编程入门 行业动态 更新时间:2024-10-27 06:26:08
本文介绍了如何在不关闭 explorer.exe 或重新启动 Windows 的情况下重建 Windows 图标缓存?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

任务

我正在尝试从我的应用程序中自定义文件夹图标,但由于 Windows 缓存图标和缩略图的方式,我正在努力获取更改后的文件夹以更新它的新图标.

在 Windows 中,我知道有两种自定义文件夹图标的方法,最简单的方法是从 Windows 资源管理器中右键单击文件夹,属性,然后选择自定义选项卡并更改其图标,但这种方法并不好因为它需要手动更改文件夹属性.

我从我的程序中做的第二种方法是创建一个 desktop.ini 文件并将其放在需要更改图标的文件夹中,desktop.ini 上的文档代码>可以在这里找到:

我完全了解 Windows 缓存图标和缩略图,我搜索并阅读了几页关于重建图标缓存的方法,从而让 Windows 显示新更改的图标而不是缓存的图标,但是我无法在不重新启动 Windows 或 Explorer.exe 进程的情况下从我的应用程序中使用它,这需要在不中断 Windows 的情况下完成,因此关闭 Explorer.exe 或要求重新启动绝对不是一种选择.

有趣的是,当从我之前描述的第一种方式更改文件夹图标时,Windows 以某种方式设法刷新并重建图标缓存,因为更改的文件夹会立即更新以显示新图标,但是我看不到 Windows 有什么技巧以实现这一目标.

尝试

我尝试过的一些失败的事情,(排名不分先后):

执行以下命令:ie4uinit.exe -ClearIconCache在 Lazarus 中运行此代码:SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil);AppData\Local 中删除 IconCache.db 文件从注册表中切换 始终显示图标,从不显示缩略图" Explorer 选项,位于此处:HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Explorer\Advanced存储在 IconsOnly 值 更改注册表中的图标大小并返回,位于此处:HKEY_CURRENT_USER\Control Panel\Desktop\WindowMetrics 存储在 Shell Icon Size 值中此链接在 Delphi 中提供了一个明显的解决方案,但我无法在 Lazarus 中进行转换:http://www.aha-soft/faq/q18.htm我知道这里有缓存的数据库文件:AppData\Local\Microsoft\Windows\Explorer 虽然我不确定它们是否有任何帮助,但尝试删除其中一些似乎是不可能的因为它们可能被锁定等.重命名文件夹,然后重命名回原始名称.右键单击 Windows 资源管理器中的空白区域,然后选择刷新"似乎也不会更新文件夹图标.

也尝试过以上的一些组合,但没有运气.

问题

当直接从 Windows 资源管理器更改文件夹图标时,使用属性上下文菜单和自定义选项卡,当应用和关闭此对话框时,文件夹图标几乎立即更改,没有关闭 explorer.exe 或重新启动 Windows,更改发生很快.

如何以与 Windows 资源管理器相同的方式从我的应用程序中实现这一点?有没有办法找出 Windows 资源管理器如何做到这一点?

我的操作系统是 Windows 10,这可以解释为什么某些旧方法对我不起作用.

解决方案

我认为这与图标缓存无关;您只需要通知资源管理器文件夹的图标已更改.您可以使用 SHChangeNotify 函数.

LPCWSTR pszFolder = L"c:\\path\\to\\folder";SHChangeNotify(SHCNE_UPDATEITEM, SHCNF_PATH, pszFolder, NULL);

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.

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/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.

Attempts

A few things I tried unsucessfully, (in no particular order):

Executing the following: ie4uinit.exe -ClearIconCache Running this code in Lazarus: SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, nil, nil); Deleting the IconCache.db file from AppData\Local 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 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 This link provides an apparent solution in Delphi which I was unable to convert in Lazarus: http://www.aha-soft/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. 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.

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.

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.

解决方案

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);

这篇关于如何在不关闭 explorer.exe 或重新启动 Windows 的情况下重建 Windows 图标缓存?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-26 01:09:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1126807.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:重新启动   缓存   图标   情况下   如何在

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!