1
私のクライアントは自分のデスクトップにインターネットのショートカット(*.url)
を持っています。私はVBアプリケーションからURLを取得し、変数として使用したいと考えています。インターネットショートカット(.url)のURLを取得するにはどうすればよいですか?
どうすればいいですか?
私のクライアントは自分のデスクトップにインターネットのショートカット(*.url)
を持っています。私はVBアプリケーションからURLを取得し、変数として使用したいと考えています。インターネットショートカット(.url)のURLを取得するにはどうすればよいですか?
どうすればいいですか?
*.lnk
と*.appref-ms
ファイルにはsample on MSDNがあります。
しかし、*.url
ファイルでも動作するようです。サイトから
引用:
ファイルがショートカットであるかどうかを確認するには、ショートカットのパスを解決するために、 COMライブラリマイクロソフトシェルコントロールとオートメーションが使用されています。この ライブラリは、Visual Studioプロジェクトの参照に追加されます。
コード:
Public Function IsShortcut(strPath As String) As Boolean
If Not File.Exists(strPath) Then
Return False
End If
Dim directory As String = Path.GetDirectoryName(strPath)
Dim strFile As String = Path.GetFileName(strPath)
Dim shell As Shell32.Shell = New Shell32.Shell()
Dim folder As Shell32.Folder = shell.NameSpace(directory)
Dim folderItem As Shell32.FolderItem = folder.ParseName(strFile)
If folderItem IsNot Nothing Then
Return folderItem.IsLink
End If
Return False
End Function
Public Function ResolveShortcut(strPath As String) As String
If IsShortcut(strPath) Then
Dim directory As String = Path.GetDirectoryName(strPath)
Dim strFile As String = Path.GetFileName(strPath)
Dim shell As Shell32.Shell = New Shell32.Shell()
Dim folder As Shell32.Folder = shell.NameSpace(directory)
Dim folderItem As Shell32.FolderItem = folder.ParseName(strFile)
Dim link As Shell32.ShellLinkObject = folderItem.GetLink
Return link.Path
End If
Return String.Empty
End Function
私が最初に何かをインポートする必要がありますか? –
COMライブラリ_Microsoftシェルコントロールとオートメーションへの参照を追加する必要があります。 'File。*'と 'Path。*'関数は 'System.IO.'-namespaceのものです – MatSnow