如何获取快捷方式文件夹的目录目标?我到处搜索,只找到快捷方式文件的目标。
我认为您将需要使用COM并添加对“ Microsoft Shell Control And Automation”的引用,如本博客文章所述:
这是使用此处提供的代码的示例:
namespace Shortcut { using System; using System.Diagnostics; using System.IO; using Shell32; class Program { public static string GetShortcutTargetFile(string shortcutFilename) { string pathOnly = System.IO.Path.GetDirectoryName(shortcutFilename); string filenameOnly = System.IO.Path.GetFileName(shortcutFilename); Shell shell = new Shell(); Folder folder = shell.NameSpace(pathOnly); FolderItem folderItem = folder.ParseName(filenameOnly); if (folderItem != null) { Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink; return link.Path; } return string.Empty; } static void Main(string[] args) { const string path = @"C:\link to foobar.lnk"; Console.WriteLine(GetShortcutTargetFile(path)); } } }