我需要从 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/