修改文件图标 [英] Modify File Icon
问题描述
我有一个VBScript可以切换代理ON和OFF。我想相应地更改文件图标,这样当代理打开时,文件图标为绿色勾号,当它处于关闭状态时,图标为红叉(表示我可以在运行前查看代理是否处于活动状态)脚本)。
I have a VBScript that toggles proxy ON and OFF. I'd like to change the file icon accordingly, so that when the proxy is ON the file icon is a green tick and when it's OFF the icon is a red cross (meaning that I can see whether the proxy is active or not before running the script).
如何以编程方式更改图标?仅适用于该文件,而非所有VBScripts!
How do I change the icon programmatically? Just for THAT file, not ALL VBScripts!
推荐答案
您无法更改特定文件的图标。但是,您可以将特定快捷方式的图标更改为文件。
You can't change the icon for a specific file. You can, however, change the icon of a specific shortcut to a file.
Set sh = CreateObject("WScript.Shell")
lnkfile = sh.SpecialFolders("Desktop") & "\your.lnk"
Set lnk = sh.CreateShortcut(lnkfile)
If lnk.IconLocation = "C:\path\to\some.ico" Then
lnk.IconLocation = "C:\path\to\.ico"
Else
lnk.IconLocation = "C:\path\to\some.ico"
End If
lnk.Save
如果快捷方式位于所有用户中桌面文件夹( C:\ Users \Public\Desktop
)您需要用<替换桌面
code>AllUsersDesktop。
If the shortcut is located in the All Users desktop folder (C:\Users\Public\Desktop
) you need to replace "Desktop"
with "AllUsersDesktop"
.
这篇关于修改文件图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!