Internet Explorerのお気に入りにどの位のインターネットショートカットが登録されているのかを調べるスクリプト(対応ファイル形式:url,website)を書いてみました。
Option Explicit
Const CSIDL_FAVORITES = 6
ListIEFavorites CreateObject("Shell.Application") _
.Namespace(CSIDL_FAVORITES).Self.Path
Private Sub ListIEFavorites(ByVal TargetFolderPath)
Dim fol, f
With CreateObject("Scripting.FileSystemObject")
If .GetFolder(TargetFolderPath).SubFolders.Count > 0 Then
For Each fol In .GetFolder(TargetFolderPath).SubFolders
ListIEFavorites fol.Path
Next
End If
If .GetFolder(TargetFolderPath).Files.Count > 0 Then
For Each f In .GetFolder(TargetFolderPath).Files
Select Case LCase(.GetExtensionName(f.Path))
Case "url"
WScript.Echo f.Path & "," & GetShortcutTargetPathFromUrl(f.Path)
Case "website"
WScript.Echo f.Path & "," & GetShortcutTargetPathFromWebsite(f.Path)
End Select
Next
End If
End With
End Sub
Private Function GetShortcutTargetPathFromUrl(ByVal TargetFilePath)
'urlファイルからショートカットファイルのリンク先取得
Dim ret
With CreateObject("WScript.Shell")
With .CreateShortcut(TargetFilePath)
ret = .TargetPath
End With
End With
GetShortcutTargetPathFromUrl = ret
End Function
Private Function GetShortcutTargetPathFromWebsite(ByVal TargetFilePath)
'websiteファイルからショートカットファイルのリンク先取得
Dim ret, s
With CreateObject("Scripting.FileSystemObject")
With .OpenTextFile(TargetFilePath)
Do Until .AtEndOfStream
s = .ReadLine
If LCase(Left(s, 4)) = "url=" Then
ret = s
Exit Do
End If
Loop
.Close
End With
End With
ret = Mid(ret, 5) '行頭の4文字(URL=)除外
GetShortcutTargetPathFromWebsite = ret
End Function
このスクリプトを実行すると、下図のようにショートカットファイルのパスとリンク先URLを出力します。

「//Nologo」オプションを付けてリダイレクトすると、CSVファイルもすぐに作れて便利です。















この記事へのコメントはありません。