© ウィンドウズスクリプトプログラマ - Windows Script Programmer 2021
インターネットショートカット(.url)のfaviconを「指定した特定フォルダ」の「ドメイン名.ico」に設定する。
インターネットショートカット(.url)を下記vbsファイルにドロップする。
FaviconFile.vbs
dir="C:\Users\ユーザ名\Desktop\Favicon\"
Set fso=CreateObject("Scripting.FileSystemObject")
For Each Path In WScript.Arguments
Path=fso.GetAbsolutePathName(Path)
SetIconPath Path
Next
Function SetIconPath(Path)
Set fso=CreateObject("Scripting.FileSystemObject")
If LCase(fso.GetExtensionName(Path))<>"url" Then Exit Function
Set File=fso.OpenTextFile(Path)
Do While Not File.AtEndOfStream
Line=LTrim(File.ReadLine)
If InStr(UCase(Line),"URL=")=1 Then
Exit Do
End If
Loop
File.Close
Icon=Mid(Line,InStr(Line,"//")+2)
Icon=Left(Icon,InStr(Icon,"/")-1)
If Icon<>"" Then
Set File=fso.OpenTextFile(Path,2)
File.WriteLine "[InternetShortcut]"
File.WriteLine Line
File.WriteLine "IconFile=" & dir & Icon & ".ico"
File.WriteLine "IconIndex=0"
File.Close
Set Link=CreateObject("WScript.Shell").CreateShortcut(Path)
link.targetpath=link.targetpath
Link.save
Else
MsgBox "no match"
End If
End Function
InternetShortcutに関連付けでおけば簡単。
Windows Registry Editor Version 5.00
[HKEY_CURRENT_USER\SOFTWARE\Classes\InternetShortcut\shell\InternetShortcut]
"SubCommands"=""
[HKEY_CURRENT_USER\SOFTWARE\Classes\InternetShortcut\shell\InternetShortcut\Shell]
[HKEY_CURRENT_USER\SOFTWARE\Classes\InternetShortcut\shell\InternetShortcut\Shell\Favicon File]
[HKEY_CURRENT_USER\SOFTWARE\Classes\InternetShortcut\shell\InternetShortcut\Shell\Favicon File\command]
@="C:\\Windows\\System32\\wscript.exe \"C:\\Users\\ユーザ名\\Desktop\\Favicon\\FaviconFile.vbs\" \"%1\""