如何获取快捷文件夹的目录目标?我到处搜索,只找到快捷方式文件的目标。
最佳答案
我认为您将需要使用 COM 并添加对“Microsoft Shell 控制和自动化”的引用,如 this blog post 中所述。 :
这是一个使用此处提供的代码的示例:
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));
}
}
}
关于c# - 获取快捷方式文件夹的目标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9414152/