有没有办法获取快捷方式的图标link?
Is there a way to get the icon of a shortcut link?
我正在尝试使用 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 但我也想要它的图标
this对你有用吗?
仅使用文件路径非常简单。
private void ExtractAssociatedIconEx()
{
Icon ico =
Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
this.Icon = ico;
}
首先确保文件存在,如果不存在,您将得到 ArgumentException
我正在尝试使用 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 但我也想要它的图标
this对你有用吗?
仅使用文件路径非常简单。
private void ExtractAssociatedIconEx()
{
Icon ico =
Icon.ExtractAssociatedIcon(@"C:\WINDOWS\system32\notepad.exe");
this.Icon = ico;
}
首先确保文件存在,如果不存在,您将得到 ArgumentException