Reputation: 93
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!
Upvotes: 2
Views: 9300
Reputation: 200283
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"
.
Upvotes: 4