2017-12-05 4 views

答えて

3

*.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 
+0

私が最初に何かをインポートする必要がありますか? –

+1

COMライブラリ_Microsoftシェルコントロールとオートメーションへの参照を追加する必要があります。 'File。*'と 'Path。*'関数は 'System.IO.'-namespaceのものです – MatSnow

関連する問題