Modify File Icon

萝らか妹 提交于 2019-12-11 02:26:29

问题


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).

How do I change the icon programmatically? Just for THAT file, not ALL VBScripts!


回答1:


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

If the shortcut is located in the All Users desktop folder (C:\Users\Public\Desktop) you need to replace "Desktop" with "AllUsersDesktop".



来源:https://stackoverflow.com/questions/26925986/modify-file-icon

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