从 Windows .lnk(快捷方式)文件中提取图标
我需要从 Windows 快捷方式 (.lnk) 文件中提取图标(或者找到图标文件,如果快捷方式只是指向它)。
我不是在询问从 exe、dll 等中提取图标。有问题的快捷方式是在我运行安装程序时创建的。 并且快捷方式显示的图标不包含在快捷方式指向的.exe中。 据推测,该图标嵌入在 .lnk 文件中,或者 .lnk 文件包含指向该图标所在位置的指针。 但我发现的实用程序都没有解决这个问题——它们都只是转到 .exe。
非常感谢!
I need to extract the icon from a windows shortcut (.lnk) file (or find the icon file, if it's just pointed to by the shortcut).
I'm not asking about extracting icons from exe's, dll's, etc. The shortcut in question is created when I run a installation program. And the icon displayed by the shortcut is not contained in the .exe that the shortcut points to. Presumably the icon is embedded in the .lnk file, or the .lnk file contains a pointer to where this icon lives. But none of the utilities I've found work address this -- they all just go to the .exe.
Many thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您还可以自己解析 .lnk 文件,请参阅此 pdf 或 这篇文章介绍了快捷方式文件格式的详细信息。
或者您可以使用 这个问题。
You can also parse the .lnk file yourself, see this pdf or this article on the details of the shortcut file format.
Or you can use the ShellLink class mentioned in the answer to this question.
我使用它来获取图标而不将快捷箭头迷你图标作为图像添加到其上:
using IWshRuntimeLibrary;
如果您希望将其作为图标获取:
I use this to get the icon without the shortcut arrow mini icon added over it as an image:
using IWshRuntimeLibrary;
If you wish to get it as an icon instead:
要添加更多资源,因为您可能不需要应用程序的图标,而不是左下角有快捷方式的图标:
To add a few more resources to this, because presumeably you wan't the Application's icon and not icon that has the shortcut in the bottom left corner:
此线程提供有关.lnk 文件中包含的数据的有趣信息< /a>
sSHGetFileInfoss 函数应该能够提取图标文件。
记录在此处,并用于 lnk 文件:
从第一个链接,您可以在 C# 中构建这样一个实用程序,您可以在其中声明此函数,如下所示:
您还可以在 autoit 脚本语言,您可以在其中使用如下声明的函数:
This thread provides interesting informations about the data contained in a .lnk file
The sSHGetFileInfoss function should be able to extract the icon file.
Documented here, and used for a lnk file:
From the first link, you could build such an utility in c#, where you would declare this function like:
You could also built an utility in autoit script language, where you would use that function declared like this:
使用 Shell32 方法访问链接:
Using the Shell32 method of acessing links:
2010 年,Microsoft 最终发布了 LNK 文件格式的官方规范。 当然,它比网上流传的逆向工程规格要准确和详细得多。
为了完整起见,这里是shell 链接和快捷方式的 MSDN 描述。
In 2010 Microsoft finally released an official specification of the LNK file format. It much more accurate and detailed than the reverse-engineered specs floating around the net, of course.
For completeness sake, here is the MSDN description of shell links and shortcuts.