我创建了一个explorer.exe克隆,包含树视图和列表视图等。
现在我需要处理点击.lnk文件,所以我需要.lnk文件的目标路径..
答案 0 :(得分:4)
您可以使用WshShell Object
:
只要您想在本地运行程序,操作注册表内容,创建快捷方式或访问系统文件夹,就可以创建WshShell对象。
并使用其CreateShortcut
方法:
创建新快捷方式,或打开现有快捷方式。
生成的WshShortcut
对象包含TargetPath
属性,这正是您要查找的内容。
示例:
Dim shell = CreateObject("WScript.Shell")
Dim path = shell.CreateShortcut(path_to_your_link).TargetPath
答案 1 :(得分:1)
我试试;
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
您需要引用COM对象; Microsoft Shell控件和自动化。