【问题标题】:Is there a way to get the icon of a shortcut link?有没有办法获取快捷链接的图标?
【发布时间】:2021-07-02 23:55:48
【问题描述】:

我正在尝试使用 C# 中的快捷方式文件打开应用程序。 现在我可以得到它的路径,但我想知道我是否也能得到它的图标? (我的意思是位于其主文件夹中的应用程序图标,而不是其快捷方式的图标) 谢谢。

现在我的代码是这样的:

 public static void DoSomeHeavyLifting()
    {
        string filepath = @"C:\Users\Hello\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar\Adobe Photoshop 2020.lnk";

        string pathOnly = filepath;
        string filenameOnly = filepath;

        Shell shell = new Shell();
        Folder folder = shell.NameSpace(pathOnly);
        FolderItem folderItem = folder.ParseName(filenameOnly);
        if (folderItem != null)
        {
            Shell32.ShellLinkObject link = (Shell32.ShellLinkObject)folderItem.GetLink;
      
            Console.WriteLine(link.Path);
        }

    }

如你所见,我只能拥有 link.Path 但我也想要它的图标

【问题讨论】:

  • 问题的标题和正文要求两种不同的东西。另外,哪个图标? Icon.ExtractAssociatedIcon()返回的Icon够不够用?或者你想提取 Jumbo 大小的图标,如果有的话?还是所有图标?还是所有可用尺寸的所有图标?
  • 向我们展示您当前的代码,告诉我们它在做什么,然后告诉我们您希望它做什么。

标签: c# winforms


【解决方案1】:

this 适合你吗?

仅与文件路径一起使用非常简单。

private void ExtractAssociatedIconEx()
{
    Icon ico =
        Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
    this.Icon = ico;
}

首先确保文件存在,否则您将获得ArgumentException

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-24
    • 1970-01-01
    • 2012-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多