Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change icon of folder with script 1

Status
Not open for further replies.

smcc12

Programmer
Jan 8, 2009
17
0
0
US
I am looking for a way to change folder icons using vbscript.. any help appreciated.

I found this script to change file icons.. but how would it work for folders?
Code:
Const DESKTOP = &H10&

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.NameSpace(DESKTOP)

Set objFolderItem = objFolder.ParseName("Test Shortcut.lnk")
Set objShortcut = objFolderItem.GetLink

objShortcut.SetIconLocation "C:\Windows\System32\SHELL32.dll", 13
objShortcut.Save
 

Not sure about doing it with VBScript but you can easily do this by using desktop.ini.

For example, let's say you have a folder called C:\CustomFolder. In that folder you have C:\CustomFolder\desktop.ini. In the desktop.ini, you would have something like:

[.ShellClassInfo]
IconFile=C:\CustomIcons\CustomFolderIcon.ico
IconIndex=0

Make the folder a system folder (e.g. attrib c:\CustomerFolder +s or do it through WMI) and tada! C:\CustomerFolder should now display with the custom icon.

You could write a VBScript to create the desktop.ini on the fly and change the folder's system property.

When you use the Change Icon button on the Customize tab of the folder properties, it just writes a desktop.ini to that folder with the contents I listed above.
 
I like what Shinedog suggests. It may not be "proper" but it's the route I would probably take. For real-life examples of his suggestion, look at the MyFolders\desktop.ini (My Documents, Music, Pictures)

-Geates
 
Thank you very much, this is exactly what I needed.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top