c# - 获取快捷方式文件夹的目标

标签 c# directory target shortcut

如何获取快捷文件夹的目录目标?我到处搜索,只找到快捷方式文件的目标。

最佳答案

我认为您将需要使用 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/

相关文章:

javascript - 使用 jQuery 加密并使用 C# 解密

directory - 如何更改 PHPStorm 8 默认的新项目位置?

python - 如何从python中的不同文件夹导入类?

c++ - create_directory (“/MyPath/.MyFolder”)未创建目录;期望创建一个隐藏目录

jquery - 在新选项卡/窗口中打开 href mailto 链接

c# - Process.Start 与“开始”>“运行”有何不同?

c# - 通过 Windows Phone 访问 WCF 服务

c# - 为了在线访问我的应用程序,我是否必须在远程主机上安装Docker?

objective-c - 如何在AppCode中创建新目标?

c++ - 如何在 Eclipse 中添加自定义构建行为