2

我做了一个 explorer.exe 克隆,带有一个树视图和一个列表视图等。

现在我需要处理单击 .lnk 文件,所以我需要 .lnk 文件的目标路径..

4

2 回答 2

6

您可以使用WshShell Object

每当您想在本地运行程序、操作注册表内容、创建快捷方式或访问系统文件夹时,您都可以创建一个 WshShell 对象。

并使用它的CreateShortcut方法:

创建新的快捷方式,或打开现有的快捷方式。

生成的WshShortcut对象包含一个TargetPath属性,这就是您要查找的内容。

例子:

Dim shell = CreateObject("WScript.Shell")
Dim path  = shell.CreateShortcut(path_to_your_link).TargetPath
于 2013-08-15T09:03:00.957 回答
2

我会尝试;

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 控件和自动化。

于 2013-08-15T08:54:48.333 回答