Pergunta

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..

Foi útil?

Solução 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.

Outras dicas

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
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top