(ZT)clear icon cache

来源:互联网 发布:163邮箱注册软件 编辑:程序博客网 时间:2024/06/16 09:31

前言

在玩一个cm.
cm有更换exe图标的行为, 如果不是cm, 有谁会搞这么扎眼的行为, 生怕别人不知道:)
在修改了注册表中HKEY_CLASSES_ROOT\exefile\DefaultIcon值为%1后, 需要刷新系统图标.
在网上找到一个人家写好的vbs, 在winxpsp3下试了好使. 用编程实现可以借鉴这个vbs, 也可以从cm中直接扒出刷新系统图标的实现.

正确的注册表导出

Windows Registry Editor Version 5.00[HKEY_CLASSES_ROOT\exefile\DefaultIcon]@="%1"

cleariconcache.vbs

'(c) 2016 Ramesh Srinivasan.'Clears the Icon Cache databases to lets Windows rebuild them fresh.'for Windows Vista, 7, 8 and Windows 10.'Written on Jan 31 2016'Updated on Apr 01 2016'http://www.winhelponline.com/blogOption ExplicitDim WshShell, objFSO, strICPath1, strICPath2, strmsg, rtnStatus, Process, iDirtyFlags, iDirtyFlags2Const DeleteReadOnly = TrueSet WshShell = WScript.CreateObject("WScript.Shell")Set objFSO = CreateObject("Scripting.FileSystemObject")strICPath1 = WshShell.ExpandEnvironmentStrings("%LOCALAPPDATA%")strICPath2 = strICPath1 & "\Microsoft\Windows\Explorer"ExitExplorerShellWScript.Sleep(3000)ClearIconCacheWScript.Sleep(2000)StartExplorerShellSub ExitExplorerShell()    strmsg = "Explorer Shell will be terminated now."    strmsg = strmsg & " Please save all your work and close all programs."    strmsg = strmsg & "Icon cache may not be cleared if programs are using them. Want to continue?"    rtnStatus = MsgBox (strmsg, vbYesNo, "Clear the Icon Cache")    If rtnStatus = vbYes Then        For Each Process in GetObject("winmgmts:"). _            ExecQuery ("select * from Win32_Process where name='explorer.exe'")            Process.terminate(1)        Next    ElseIf rtnStatus = vbNo Then        WScript.Quit    End IfEnd SubSub StartExplorerShell    WshShell.Run "explorer.exe"End SubSub ClearIconCache()    If (objFSO.FileExists(strICPath1 &"\IconCache.db")) Then    On Error Resume Next        objFSO.DeleteFile strICPath1 &"\IconCache.db", DeleteReadOnly    On Error Goto 0        If Err.Number <> 0 AND Err.Number <> 53 Then            iDirtyFlags = 1        End If    End If    If objFSO.FolderExists(strICPath2) Then    On Error Resume Next        objFSO.DeleteFile(strICPath2 & "\icon*.db"), DeleteReadOnly    On Error Goto 0        If Err.Number <> 0 AND Err.Number <> 53 Then            iDirtyFlags2 = 1        End If          End If    WshShell.Run "ie4uinit.exe -ClearIconCache"    WshShell.Run "ie4uinit.exe -show"End SubIf iDirtyFlags = 1 Then    rtnStatus = MsgBox ("Some programs are still using the IconCache.db in LOCALAPPDATA. Close all programs and try again", vbOKonly, "Clear the Icon Cache")End IfIf iDirtyFlags2 = 1 Then    If iDirtyFlags <> 1  Then        rtnStatus = MsgBox ("Some programs are still using the cache in Location 2. Close all programs and try again", vbOKOnly, "Clear the Icon Cache")    End IfEnd IfIf iDirtyFlags = 0 And iDirtyFlags2 = 0 Then    MsgBox "Successfully cleared the Icon Caches.", vbOKOnly, "Clear the Icon Cache"End IfSet WshShell = NothingSet objFSO = Nothing
0 0
原创粉丝点击