문제

I made a explorer.exe clone, with a treeview and a listview etc.

Now I need to handle clicking a .lnk file, so I need the destination path of a .lnk file..

도움이 되었습니까?

해결책 2

I'd try;

Public Shared Function GetLnkTarget(lnkPath As String) As String
    Dim shl = New Shell32.Shell()
    ' Move this to class scope
    lnkPath = System.IO.Path.GetFullPath(lnkPath)
    Dim dir = shl.[NameSpace](System.IO.Path.GetDirectoryName(lnkPath))
    Dim itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath))
    Dim lnk = DirectCast(itm.GetLink, Shell32.ShellLinkObject)
    Return lnk.Target.Path
End Function

You need to reference a COM object; Microsoft Shell Controls And Automation.

다른 팁

You can use a WshShell Object:

You create a WshShell object whenever you want to run a program locally, manipulate the contents of the registry, create a shortcut, or access a system folder.

and use its CreateShortcut method:

Creates a new shortcut, or opens an existing shortcut.

The resulting WshShortcut object contains a TargetPath property, which is what you're looking for.

Example:

Dim shell = CreateObject("WScript.Shell")
Dim path  = shell.CreateShortcut(path_to_your_link).TargetPath
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top