2

我找到了这段代码:

    Public Shared Function GetLnkTarget(ByVal 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

它适用于一些 .lnk 文件,但例如,如果我添加我的 Skype.exe 桌面链接,它会产生:

C:\Windows\Installer\{...}\SkypeIcon.exe

有解决办法吗?

4

2 回答 2

1

尝试这个:

Function GetTargetPath(ByVal FileName As String)

    Dim Obj As Object
    Obj = CreateObject("WScript.Shell")

    Dim Shortcut As Object
    Shortcut = Obj.CreateShortcut(FileName)
    GetTargetPath = Shortcut.TargetPath


End Function

    Private Sub Teste_Load(sender As Object, e As EventArgs) Handles MyBase.Load 

MsgBox(GetTargetPath("C:\ProgramData\Microsoft\Windows\Start Menu\BitTorrent.lnk"))

'here you chose the location of .lnk file

End Sub
于 2013-06-20T11:35:50.963 回答
0

CreateShortcut() 对于某些在属性中具有灰色目标的快捷方式(如 Adob​​e Reader 和 Microsoft Word)无法按预期工作。目标路径最终成为 c:\windows\installer (图标?)下的东西。

于 2017-08-10T21:22:06.120 回答