我找到了这段代码:
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
有解决办法吗?
尝试这个:
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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)