在 Windows 中更改 desktop.ini 不会自动更新文件夹图标 [英] Changing desktop.ini doesn't update folder icon automatically in Windows
问题描述
我正在使用此批处理脚本将所有文件夹和子文件夹的图标更改为位于文件夹中的 .ico 文件.
I'm using this batch script to change the icons of all the folders and sub-folders to the .ico files that are located in the folders.
但是,文件夹图标在资源管理器中不会改变,除非我在资源管理器中手动将 desktop.ini
文件重命名为其他文件,然后重新命名为 desktop.ini
或例如将字母更改为大写.
However the folder icons do not change in Explorer unless I manually rename desktop.ini
file in Explorer to something else and then back to desktop.ini
or change the letters to uppercase for example.
我什至写了一个批处理函数来自动重命名desktop.ini,但它不起作用.
I even wrote a batch function to automatically rename the desktop.ini but it doesn't work.
手动重命名和从批处理文件重命名有什么区别,如何让资源管理器使用新的 desktop.ini
?
What is the difference between renaming them manually and renaming it from a batch file and how can I make Explorer use the new desktop.ini
?
@echo off
for /r %%I in (*.ico) do (
attrib -r -s "%%~dpI." /S /D
if exist %%~dpIdesktop.ini (
del "%%~dpIdesktop.ini"
)
>>%%~dpIdesktop.ini echo [.ShellClassInfo]
>>%%~dpIdesktop.ini echo IconResource="%%~nI%%~xI",0
attrib -h desktop.ini /S
attrib +r -s "%%~dpI." /S /D
)
推荐答案
使用 shell
函数将通知所有正在运行的资源管理器窗口使用更新的 desktop.ini
.此 API 通过 Shell 在 VBScript 中公开.Application.NameSpace("folder\").MoveHere:
Use a shell
function that will notify all running Explorer windows to use the updated desktop.ini
. This API is exposed in VBScript via Shell.Application.NameSpace("folder\").MoveHere:
@echo off
for /r %%I in (*.ico) do (
attrib -h -s -r "%temp%\desktop.ini" >nul
(
echo [.ShellClassInfo]
echo IconResource="%%~nxI",0
)>"%temp%\desktop.ini"
attrib +h +s "%temp%\desktop.ini"
(
echo set shell = CreateObject^("Shell.Application"^)
echo set folder = shell.NameSpace^("%%~dpI"^)
echo folder.MoveHere "%temp%\desktop.ini", 4+16+1024
)>"%temp%\updateIcon.vbs"
cscript //nologo //b "%temp%\updateIcon.vbs"
)
pause
附言我忘记了 VB 的大部分内容,所以记得它的人可能会在 VBS(嵌入式)中重写整个代码.
P.S. I forgot most of VB so whoever remembers it may rewrite the entire code in VBS (embedded).
这篇关于在 Windows 中更改 desktop.ini 不会自动更新文件夹图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!