VBScript

Internet Explorerのお気に入りを列挙するVBScript

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ファイルもすぐに作れて便利です。

2017年4月の人気記事前のページ

Microsoft Edgeの場所次のページ

関連記事

  1. VBScript

    画像の一部にぼかしを入れるバッチ処理

    Paint.NETなどの画像処理ソフトを使うと、簡単に画像にぼかしを入…

  2. VBScript

    文字コードを指定してURLエンコードを行う

    本題に入る前にまずは下記エントリーをご覧ください。・64ビット…

  3. VBScript

    Office付属のVBEでVBScriptコードを書くのを助けるVBScript

    VBScriptのコードを書くとき、メモ帳等のテキストエディタではイン…

  4. VBScript

    Windowsのバージョン情報を取得する

    小ネタです。verコマンドを利用してWindowsのバージ…

  5. VBScript

    Adobe Illustratorを操作するVBScript

    Acrobatと同様にタイプライブラリが用意されているため、VBAやV…

  6. Windows 10

    Microsoft Edgeを操作するVBScript

    「Microsoft Edgeを操作するVBAマクロ(WebDrive…

コメント

  • コメント (0)

  • トラックバックは利用できません。

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

Time limit is exhausted. Please reload CAPTCHA.

※本ページはプロモーションが含まれています。

Translate

最近の記事

アーカイブ

PAGE TOP