开发者

Batch Script - Change Icon of a Folder on Desktop (Windows XP)

How 开发者_运维知识库would I go about changing a desktop folder's icon/image via the command line/batch script in windows xp?

I will be creating an event in one of my scripts to change the icon to an image of an exclamation point when a new file is inserted into a folder to alert users.


Save your image.ico to desktop.
The following will make a test folder on the desktop as well as the desktop.ini file linking the image file you wish to use.

CD "%userprofile%\desktop"
MKDIR "TEST FOLDER"
ATTRIB +s "TEST FOLDER"
CD "TEST FOLDER"
COPY /Y "%userprofile%\desktop\image.ico" "./image.ico"
ECHO [.ShellClassInfo] >> desktop.txt
ECHO ConfirmFileOp=0 >> desktop.txt
ECHO NoSharing=1 >> desktop.txt
ECHO IconFile=image.ico >> desktop.txt
ECHO IconIndex=0 >> desktop.txt
ECHO InfoTip= >> desktop.txt
CHCP 1252 >NUL
CMD.EXE /D /A /C (SET/P=ÿþ)<NUL > desktop.ini 2>NUL
CMD.EXE /D /U /C TYPE desktop.txt >> desktop.ini
DEL /F /Q desktop.txt
ATTRIB +S +H desktop.ini image.ico

The image shows up instantaneously as long as it is a new folder (not one that was deleted and recreated. You just 'mkdir' a folder that was recently deleted, the desktop will need to be refreshed to see the changes (caching?).


You should place desktop.ini file inside folder. Look here

http://perishablepress.com/press/2006/10/16/folder-background-images-in-winxp/

http://msdn.microsoft.com/en-us/library/cc144102(v=vs.85).aspx


Answer by "Mechaflash" didn't work for me on my system (Windows XP SP3) . . . but this worked:
Open a work folder and drop an icon inside it ("Desktop.ini.ico") and this batch file:

@ECHO OFF  
PUSHD "%~dp0"  
MKDIR "NEW CUSTOM FOLDER"  
ATTRIB -R "NEW CUSTOM FOLDER"  
ATTRIB -H -R "NEW CUSTOM FOLDER\Desktop.ini.ico"  
ATTRIB -H -R "NEW CUSTOM FOLDER\Desktop.ini"  
COPY /Y "Desktop.ini.ico" "NEW CUSTOM FOLDER\Desktop.ini.ico"  
ECHO [.ShellClassInfo] > "NEW CUSTOM FOLDER\Desktop.ini"  
ECHO IconFile=Desktop.ini.ico >> "NEW CUSTOM FOLDER\Desktop.ini"  
ECHO IconIndex=0 >> "NEW CUSTOM FOLDER\Desktop.ini"  
ECHO InfoTip=This folder InfoTip text is inside "Desktop.ini" >> "NEW CUSTOM FOLDER\Desktop.ini"  
ATTRIB +H +R "NEW CUSTOM FOLDER\Desktop.ini.ico"  
ATTRIB +H +R "NEW CUSTOM FOLDER\Desktop.ini"  
ATTRIB +R "NEW CUSTOM FOLDER"  
POPD  
EXIT  

Double-click the batch file and voila, there is your "NEW CUSTOM FOLDER" inside your work folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜