How to change existing folder's icon via Command Line? (Windows 10)

丶灬走出姿态 提交于 2020-06-23 11:02:42

问题


I have a folder on my desktop and 12 different icons. I want to create a scheduled task with Task Scheduler that runs as long as my PC is on and changes the icon of the folder every 15 minutes.

I have done my research and I found this code:

`attrib -h -r c:\test\desktop.ini
echo [.ShellClassInfo] >C:\test\desktop.ini
echo IconFile=%SystemRoot%\system32\shell32.dll>>C:\test\desktop.ini
echo IconIndex=0 >>C:\test\desktop.ini
attrib +h +r c:\test\desktop.ini
attrib +r c:\test`

However, I have no clue on how to implement/amend this to execute the task that I want to. I would not like a Batch file appearing on my Desktop.

Any help would be appreciated. Thanks.


回答1:


I was able to make a working model here:

Set DriveLetter=C    
Set Pathing=test    
Set IconPath=users\username\desktop\icon.ico    
attrib -s -h -r %DriveLetter%:\%Pathing%\desktop.ini    
echo [.ShellClassInfo] >%DriveLetter%:\%Pathing%\desktop.ini    
echo IconFile=%DriveLetter%:\%IconPath%>>%DriveLetter%:\%Pathing%\desktop.ini    
echo IconIndex=0 >>%DriveLetter%:\%Pathing%\desktop.ini    
attrib +s +h +r %DriveLetter%:%Pathing%\desktop.ini    
attrib +s +r %DriveLetter%:\%Pathing%    
pause

Please note the following:

This doesn't require the need for "DriveLetter" I just like adding that to my scripts (Though having the drive letter specified is required, you just don't need the extra option it can be merged in with the path[Pathing] Option)

DriveLetter= The drive you want it on

Pathing= the path to the folder in question you wish to change

Iconpath= the full path to the icon's location

The result is I have a folder located @ E:\test\ that has the icon in question

you should be able to run that code and get output by only editing the top 3 lines, or you could write it in manually.




回答2:


You can use below script that I found it here.

If [%1] == [] goto :eof
ECHO [.ShellClassInfo] >%1\desktop.in
ECHO IconResource=C:\icon.ico,0 >>%1\desktop.in
move %1\desktop.in %1\desktop.ini
attrib +S +H %1\desktop.ini
attrib +R %1


来源:https://stackoverflow.com/questions/37095448/how-to-change-existing-folders-icon-via-command-line-windows-10

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!