Can I embed an icon to a .hta file?

hta
40,686

Solution 1

I've found an hack to set the icon.

Prepare an icon file icon.ico and an hta file source.hta with the following contents:

<HTML>
<HEAD>
   <SCRIPT>
      path = document.URL;
      document.write(
       '<HTA:APPLICATION ID="oHTA" APPLICATIONNAME="myApp" ICON="'+path+'">');
   </SCRIPT>
</HEAD>
<BODY SCROLL="no">
  Hello, World!
</BODY>
</HTML>

Open a command prompt and type:

copy /b icon.ico+source.hta iconapp.hta

That will concatenate the icon and hta into a single file.

In my test case Internet explorer skipped over the icon data and display the HTML correctly.

The path of the icon is then set to that of the .hta file itself using javascript and the icon is loaded.

I have tested this on Windows XP SP3, Internet explorer 8.

Solution 2

I remember seeing this a looong time ago:

<img src="data:image/gif;base64,R0lGODlhEAAOALMAAOazToeHh0tLS/7LZv/0jvb29t/f3//Ub//ge8WSLf/rhf/3kdbW1mxsbP//mf///yH5BAAAAAAALAAAAAAQAA4AAARe8L1Ekyky67QZ1hLnjM5UUde0ECwLJoExKcppV0aCcGCmTIHEIUEqjgaORCMxIC6e0CcguWw6aFjsVMkkIr7g77ZKPJjPZqIyd7sJAgVGoEGv2xsBxqNgYPj/gAwXEQA7"width="16" height="14" alt="embedded folder icon">

I've never tried it myself though.

Solution 3

I know it's not exactly what the OP requested, but, instead of embedding an icon in the .hta, have you consider a URL to an icon file? Many websites have a website icon favicon.ico which works in HTA applications:

<HTML>
<HEAD>
   <HTA:APPLICATION
       ID="oHTA"
       APPLICATIONNAME="myApp"
       ICON="http://stackoverflow.com/favicon.ico">
</HEAD>
<BODY SCROLL="no">
  Hello, World!
</BODY>
</HTML>

This gives you limitless choices in icons without the need to deploy one with your HTA application.

Solution 4

Another possible solution, but not completely compliant with the exact phrasing of the question, would be to convert the HTA into an .EXE file using the "HTAedit" application (http://www.htaedit.com/).

They offer a trial version that is compltely functional (just some startup nag screen and no history/recent files) without blocking creation of .EXE from the HTA source, with no time limit.

You can then declare your icon with the ICON="myicon.ico" statement in the HTA header block, then when it "compiles" (according to my opinion it's more likely rather a packager than a real compiler but that's not the point here) it ask you for additional resource files. If your icon file is not already listed there, then just add it into the list, "et voilà !". You get a nice executable with it's version number and embedded icon.

Actually that's what I did with the Microsoft Scripting Guys tools (HTA_HELPOMATIC.HTA and SCRIPTOMATIC.HTA): I just changed them in EXE adding an icon from some %windir%\system32 exe/dll I found matching more or less the meaning of the tools, and it worked perfectly.

On the run it might be more portable than just embedding the icon into the HTA (HTAedit tool seems to be able to produce W7/64 executables but I did not test it that way, I'm still under XP32-SP2...) and it keeps your source hta file readable and editable by a text editor.

Solution 5

Quite possibly ... there is a way to embed images directly into an html file that may work for this http://www.sveinbjorn.org/news/2005-11-28-02-39-23

Share:
40,686
BoltBait
Author by

BoltBait

BoltBait is a C#/JS/SQL programmer in the insurance industry. He was a programmer for the Intel Corporation for 23 years until he retired. He wrote the most downloaded dominoes game at download.com. He also writes plugins for Paint.NET and is the current maintainer of CodeLab which is a free (as in free beer) development environment for writing Paint.NET plugins. BoltBait has a wife, 4 children, 2 grandchildren, and a cat. And, yes, he drew that picture of himself using Paint.NET

Updated on October 14, 2022

Comments

  • BoltBait
    BoltBait over 1 year

    I have written an HTML Application (hta file) and am wondering if there is a way to embed an icon file into the hta file itself.

    I have seen html emails that include embedded graphic files, is there any way to do this with html applications and icons?

    HTA files have an HTA:APPLICATION tag that allows you to specify an icon, but I want to have only a single file for download. I don't want to have an external icon file. Is this possible?

    More info on hta files here: HTA files.