Windows图标缓存导致的一个诡异BUG

最近在WIN7下开发的P2P程序,在代码里更换了新图标,客户端运行的托盘程序在退出时弹messagebox时任务栏上仍然显示的是老版本的图标(托盘上的图标是正常的)。

WIN7下使用没有那么严重,一般情况下,如果遇到这个问题,删除这个托盘程序的目录下所有文件,然后重启系统,重新加载运行后该问题消失。

但在WINXP和WIN8下就很顽固了,采用前述方法问题依旧(WIN8与WINXP有一点区别,直接在程序当前目录下双击运行,弹消息窗时显示老版图标的只有WIN8,WINXP却是显示的新版图标)。于是想到2套解决方案:

1,尝试在系统下新建用户帐号作为walk around,问题解决,说明系统有很大的因素。

2,也曾考虑分别在WIN8和WINXP下搭建开发环境并build,一来effort不够,二来并不一定会奏效。

后来发现这个WINDOWS很让人讨厌的BUG,比DLL HECK都难受!下面是一些解决方案:

  • Install Microsoft's TweakUI and run the option to rebuild icons(此链接已经失效).
  • Or increase the icon cache size. Go to HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer and add a new String Value called Max Cached Icons. The default value is 500 - try increasing it to 2048 (see Q132668 in the Microsoft knowledge base for more details).
  • Or delete the file called ShellIconCache in your Windows directory. And reboot.(经验证,WIN7、WIN8下均无此文件!)

  • If you find that one or more of your icons are not displaying correctly, or that your icon cache is corrupted, you might want to consider rebuilding your icon cache.

             To do so, Open Windows Explorer, and configure your Folder Options > Views to show Hidden / System Files. Next go to C:\Users\Owner\AppData\Local folder and delete the hiddenIconCache.db file. Reboot.This action will purge and rebuild the icon cache.

             There is also another way to do it, should the above method not work for you.

             Kill Explorer.exe process. To do so, click Start button > Hold down Ctrl+Shift & Right Click on empty area in the Start Menu > Click “Exit Explorer”.

             Click Ctrl+Shift+Esc keys and open Task Manager.

             Click File > New Task > cmd.exe > OK. This will open the command prompt.

             Type cd /d %userprofile%\AppData\Local
             Click OK
             Type attrib –h IconCache.db
             Click OK
             Type del IconCache.db
             Click OK
             Type start explorer
             Click OK.

             Your Windows Icon Cache would have been rebuilt.(验证过了,无效!)

最后,用WINPE引导机器进入系统后删除那个iconcache.db文件后重启,仍然无效!太顽固了,看来适合我目前遇到的case的解决方案还没有,只能walk around了。

你可能感兴趣的:(Programming)