2017-12-05 13 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.' 네임 스페이스에 있습니다. – MatSnow