如何在HTA中获取文件的关联图标(HTML / Javascript / VBScript)

时间:2021-11-22 21:48:25

I'm building an HTA application in which I need to display a list of file with their associated system icon.
I'm using FileSystemObject to list the file but there seem to have no way to get the icon...

我正在构建一个HTA应用程序,我需要在其中显示一个文件列表及其相关的系统图标。我正在使用FileSystemObject列出文件,但似乎无法获取图标......

I've found a script in VBS that can save the icon of a file into a .ico .
It read the file (PE resource file, .exe or dll) and parse the icon data. I modified that script to return the icon's bytes, convert it to base64 and use embed base64 images in HTML. Here's the original script: http://gilpin.us/IconSiphon/

我在VBS中找到了一个可以将文件图标保存为.ico的脚本。它读取文件(PE资源文件,.exe或dll)并解析图标数据。我修改了该脚本以返回图标的字节,将其转换为base64并在HTML中使用嵌入的base64图像。这是原始脚本:http://gilpin.us/IconSiphon/

Issue

  1. ) In most case the .ico contains multiple icons (many sizes and color depth) but there's no way I can specify which one to use (as I need 16x16 icons).

    )在大多数情况下,.ico包含多个图标(许多尺寸和颜色深度),但我无法指定使用哪个(因为我需要16x16图标)。

  2. ) Not all icons are displayed

    )并非所有图标都显示

  3. ) Could be slow with many file as it read exe and dll (but I'm ok with that, I can cache already fetched icon)

    )因为它读取exe和dll,所以文件可能很慢(但是我很好,我可以缓存已经获取的图标)

I've also tried some ActiveX control but none seem to work properly. Even those provided by microsoft (ShellFolderView or ListView) are very buggy.

我也试过一些ActiveX控件,但似乎都没有正常工作。即使是微软提供的那些(ShellFolderView或ListView)也是非常错误的。

Requirements

  • Must display 16x16 icon

    必须显示16x16图标

  • Must allow multiple file selection

    必须允许多个文件选择

  • Everything must be embed in hta (if possible). No external .exe

    一切都必须嵌入hta(如果可能的话)。没有外部.exe

Does anyone know a way to achieve that?

有谁知道实现这一目标的方法?

Thanks!

4 个解决方案

#1


1  

Use SHGetFileInfo() with the SHGFI_ICON flag.

将SHGetFileInfo()与SHGFI_ICON标志一起使用。

http://msdn.microsoft.com/en-us/library/windows/desktop/bb762179(v=vs.85).aspx

#2


1  

The filesystemobject will provide you the necessary functions for enumerating files on the local filesystem. However to get the icon image you will need to use the win32 api per @seanchase's response or an external exe.

filesystemobject将为您提供枚举本地文件系统上的文件所需的功能。但是要获取图标图像,您需要使用win32 api per @seanchase的响应或外部exe。

However you can access the win32api via javascript in the hta using the wshApiToolkit activex object - http://www.google.com/search?q=wshAPIToolkit.ucATO%2F&rls=com.microsoft:en-us&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1

但是,您可以使用wshApiToolkit activex对象通过hta中的javascript访问win32api - http://www.google.com/search?q=wshAPIToolkit.ucATO%2F&rls=com.microsoft:en-us&ie=UTF-8&oe=UTF -8的startIndex =&起始页= 1

Find a copy of that and you're close to being done. It does require distributing the activex object with your code and shell executing the registration process from within the HTA so that might violate your third constraint. Though I believe you can base64 encode the exe into the hta in a dataurl and write that back out to the file system so it would at least be bundled into a single file. If you support that option then maybe embedding an exe that does the same would meet your requriements.

找到一份副本,你即将完成。它确实需要使用您的代码和shell分配activex对象,从而在HTA中执行注册过程,这样可能会违反您的第三个约束。虽然我相信你可以在数据包中将exe64编码到hta中并将其写回文件系统,因此它至少会被捆绑到一个文件中。如果您支持该选项,那么可能嵌入一个执行相同操作的exe将满足您的要求。

Definitely some hacky stuff that may be unstable on future OS versions - heck I'm not even sure the wshApiToolkit works on windows 7, and 8 is just around the corner. Good luck!

绝对是一些可能在未来的操作系统版本上不稳定的hacky东西 - 哎呀我甚至不确定wshApiToolkit在Windows 7上运行,而且8就在眼前。祝你好运!

#3


1  

You indicated you're opened to installing ActiveX components and using them in your HTA.

您表示您已打开安装ActiveX组件并在HTA中使用它们。

If I had the time, I would approach this for myself by creating ActiveX components using Visual Studio to call FindResource, LoadResource and LockResource. These will enable access to the Group Icon resource for which I would then provide rich interfaces to iterate through the Icons offering the ability to extract BMPs (or PNGs).

如果我有时间,我会通过使用Visual Studio创建ActiveX组件来调用FindResource,LoadResource和LockResource来为自己解决这个问题。这些将允许访问组图标资源,然后我将提供丰富的接口来迭代通过提供提取BMP(或PNG)的图标的图标。

This is "how" I would go about achieving this short of actually going off doing it.

这就是“如何”实现这样做的实际目标。

#4


1  

Once I build a similar HTA interface and I faced the same problem. I solved the problem by creating a custom icon gallery and converting the images using base64. You may achieve the same by either converting or using sprite. Many UI does it, even java.swing has its own collection embbebed. As you noticed, reading from *.dll can speed down the application

一旦我构建了类似的HTA接口,我就遇到了同样的问题。我通过创建自定义图标库并使用base64转换图像来解决问题。您可以通过转换或使用精灵来实现相同的目标。很多UI都做到了,甚至java.swing都有自己的集合嵌入。正如您所注意到的,从* .dll读取可以加速应用程序

#1


1  

Use SHGetFileInfo() with the SHGFI_ICON flag.

将SHGetFileInfo()与SHGFI_ICON标志一起使用。

http://msdn.microsoft.com/en-us/library/windows/desktop/bb762179(v=vs.85).aspx

#2


1  

The filesystemobject will provide you the necessary functions for enumerating files on the local filesystem. However to get the icon image you will need to use the win32 api per @seanchase's response or an external exe.

filesystemobject将为您提供枚举本地文件系统上的文件所需的功能。但是要获取图标图像,您需要使用win32 api per @seanchase的响应或外部exe。

However you can access the win32api via javascript in the hta using the wshApiToolkit activex object - http://www.google.com/search?q=wshAPIToolkit.ucATO%2F&rls=com.microsoft:en-us&ie=UTF-8&oe=UTF-8&startIndex=&startPage=1

但是,您可以使用wshApiToolkit activex对象通过hta中的javascript访问win32api - http://www.google.com/search?q=wshAPIToolkit.ucATO%2F&rls=com.microsoft:en-us&ie=UTF-8&oe=UTF -8的startIndex =&起始页= 1

Find a copy of that and you're close to being done. It does require distributing the activex object with your code and shell executing the registration process from within the HTA so that might violate your third constraint. Though I believe you can base64 encode the exe into the hta in a dataurl and write that back out to the file system so it would at least be bundled into a single file. If you support that option then maybe embedding an exe that does the same would meet your requriements.

找到一份副本,你即将完成。它确实需要使用您的代码和shell分配activex对象,从而在HTA中执行注册过程,这样可能会违反您的第三个约束。虽然我相信你可以在数据包中将exe64编码到hta中并将其写回文件系统,因此它至少会被捆绑到一个文件中。如果您支持该选项,那么可能嵌入一个执行相同操作的exe将满足您的要求。

Definitely some hacky stuff that may be unstable on future OS versions - heck I'm not even sure the wshApiToolkit works on windows 7, and 8 is just around the corner. Good luck!

绝对是一些可能在未来的操作系统版本上不稳定的hacky东西 - 哎呀我甚至不确定wshApiToolkit在Windows 7上运行,而且8就在眼前。祝你好运!

#3


1  

You indicated you're opened to installing ActiveX components and using them in your HTA.

您表示您已打开安装ActiveX组件并在HTA中使用它们。

If I had the time, I would approach this for myself by creating ActiveX components using Visual Studio to call FindResource, LoadResource and LockResource. These will enable access to the Group Icon resource for which I would then provide rich interfaces to iterate through the Icons offering the ability to extract BMPs (or PNGs).

如果我有时间,我会通过使用Visual Studio创建ActiveX组件来调用FindResource,LoadResource和LockResource来为自己解决这个问题。这些将允许访问组图标资源,然后我将提供丰富的接口来迭代通过提供提取BMP(或PNG)的图标的图标。

This is "how" I would go about achieving this short of actually going off doing it.

这就是“如何”实现这样做的实际目标。

#4


1  

Once I build a similar HTA interface and I faced the same problem. I solved the problem by creating a custom icon gallery and converting the images using base64. You may achieve the same by either converting or using sprite. Many UI does it, even java.swing has its own collection embbebed. As you noticed, reading from *.dll can speed down the application

一旦我构建了类似的HTA接口,我就遇到了同样的问题。我通过创建自定义图标库并使用base64转换图像来解决问题。您可以通过转换或使用精灵来实现相同的目标。很多UI都做到了,甚至java.swing都有自己的集合嵌入。正如您所注意到的,从* .dll读取可以加速应用程序