Put this in a vbs file and run in the cmd with the argument being the folder the folders are in
EditDesktopIni(Wscript.Arguments(0))
Sub EditDesktopIni(foldpath)
Dim fso, inifile, icondata, file, fold, subfold, item
Const ForReading = 1, ForWriting = 2
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set fold = fso.GetFolder(foldpath)
Set subfold = fold.SubFolders
For Each item In subfold
If (fso.FileExists(foldpath + "\" + item.Name + "\desktop.ini")) Then 'If desktop.ini exists, delete it
fso.DeleteFile foldpath + "\" + item.Name + "\desktop.ini", True
End If
Set file = fso.OpenTextFile(foldpath + "\" + item.Name + "\desktop.ini", ForWriting, True, TristateUseDefault)
file.WriteLine "[.ShellClassInfo]"
file.WriteLine "IconResource=" & foldpath & "\" & item.name & ".ico" & ",0"
file.WriteLine "[ViewState]"
file.WriteLine "Mode="
file.WriteLine "Vid="
file.WriteLine "FolderType=Generic"
file.WriteLine ""
fso.GetFile(foldpath + "\" + item.Name + "\desktop.ini").Attributes = 6
Next
End Sub
Notes:
- I got the text in desktop.ini file from a test folder in a Windows 7 com. I am not sure if it will work on other versions of windows.
- I have tested the code but the icons only update after some time and some refreshes
EDIT: This one works instantly (and the code is much nicer):
EditDesktopIni(Wscript.Arguments(0))
Sub EditDesktopIni(foldpath)
Dim fso, inifile, icondata, file, fold, subfold, item, subfoldpath
Const ForReading = 1, ForWriting = 2
Const TristateUseDefault = -2, TristateTrue = -1, TristateFalse = 0
Set fso = CreateObject("Scripting.FileSystemObject")
Set fold = fso.GetFolder(foldpath)
Set subfold = fold.SubFolders
For Each item In subfold
inifile = foldpath + "\" + item.Name + "\desktop.ini"
subfoldpath = foldpath & "\" & item.name
If (fso.FileExists(inifile)) Then 'If desktop.ini exists, delete it
fso.DeleteFile inifile, True
End If
Set file = fso.OpenTextFile(inifile, ForWriting, True, TristateUseDefault)
file.WriteLine "[.ShellClassInfo]"
file.WriteLine "IconResource=" & subfoldpath & ".ico" & ",0"
file.WriteLine "[ViewState]"
file.WriteLine "Mode="
file.WriteLine "Vid="
file.WriteLine "FolderType=Generic"
file.WriteLine ""
fso.GetFile(inifile).Attributes = 6
item.Attributes = 0
item.Attributes = 4 'Set the folder to system to refresh the icon
Next
End Sub