windows - 从 Windows .lnk(快捷方式)文件中提取图标

标签 windows icons shortcut

我需要从 Windows 快捷方式 (.lnk) 文件中提取图标(或者找到图标文件,如果它只是由快捷方式指向的话)。

我不是在询问从 exe、dll 等文件中提取图标的问题。相关快捷方式是在我运行安装程序时创建的。并且快捷方式显示的图标不包含在快捷方式指向的.exe中。推测该图标嵌入在 .lnk 文件中,或者 .lnk 文件包含指向该图标所在位置的指针。但是我找到的实用程序都没有解决这个问题——它们都只是转到 .exe。

非常感谢!

最佳答案

使用Shell32方法获取链接:

String lnkPath = @"C:\Users\PriceR\Desktop\Microsoft Word 2010.lnk";
//--- run microsoft word
var shl = new Shell32.Shell();         // Move this to class scope
lnkPath = System.IO.Path.GetFullPath(lnkPath);
var dir = shl.NameSpace(System.IO.Path.GetDirectoryName(lnkPath));
var itm = dir.Items().Item(System.IO.Path.GetFileName(lnkPath));
var lnk = (Shell32.ShellLinkObject)itm.GetLink;
//lnk.GetIconLocation(out strIcon);
String strIcon;
lnk.GetIconLocation(out strIcon);
Icon awIcon = Icon.ExtractAssociatedIcon(strIcon);
this.button1.Text = "";
this.button1.Image = awIcon.ToBitmap();

关于windows - 从 Windows .lnk(快捷方式)文件中提取图标,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/343200/

相关文章:

netbeans - 如何在netbeans IDE 8.3中使用快捷键添加多行注释/* */

c - 在 C system() 函数中隐藏控制台,Win

php - 使路径在 Linux 和 Windows 上都有效

c++ - 在 C\C++ 中使用 XML 创建 GUI

flutter - 如何使图标可点击并将其重定向到 flutter 中的 URL

android - 操作栏图标大小

windows - 在 Windows 中删除符号链接(symbolic link)

c# - 在用户提供时获取代码中的 Windows 特殊文件夹

java - 在 ToolTipText 上使用图标

eclipse - Eclipse 中添加注释代码的快捷按钮