tags:

views:

3509

answers:

9

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.

A: 

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

Buzz
+1  A: 

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.

Diodeus
That is a dataURL, and it would be a good solution except IE doesn't support them until version 8.
Joel Anair
A: 

I've tried this myself, and never got it to work correctly... I tried with a smaller image, and still no luck... I will have a look at this again, and see if I can figure out what is going on, and will post my results...

LarryF
A: 

IE doesn't support data URIs, so you're going to have to use an external file if you use the img tag.

The only thing I can think of is to use VML, which has been around since IE5. It's an SVG-like vector image format that can be used inline. For example, draw something using this VML editor and click "Get code". You can plop that in your HTA. I'm not aware of anything that will convert your image to VML directly, but I believe there is a way to export to VML from some Office products.

seisyll
A good point for graphics in the HTA, but not for the icon specified in the <hta:application> tag.
Joel Anair
Ah, you're right. Whoops.
seisyll
A: 

It's a pretty far-fetched answer, but you could embed the icon as base64-encoded XML in the HTA, then use JavaScript onload and save the icon file to a temporary location. The ActiveX Object MSXML.DomDocument can encode and decode base64 nodes.

Joel Anair
This sounds very promising. Could you show me some sample code? My HTA file can be downloaded from http://www.boltbait.com/htmleditor/ Thanks!
BoltBait
A: 

As soon as you need an <iframe> or other HTML dialog you're going to want additional files anyway. You'll generaly find that .CSS and .VBS files separate from the .HTA make programming and support a lot easier for any non-trivial HTA too.

One alternative for doing this as "a single EXE" is to wrap everything up as a self-extracting archive or via IExpress. When the user "runs your program" it extracts everything from your archive into a temp directory and runs the item of your choice.

There are 3rd party alternatives like HTMLApp too.

Bob Riemersma
+2  A: 

Consider using one of the applications in System32 for your icon.

This won't change the icon for an HTA file that's on the desktop, but once it's running it will add some personality to the task bar and such.

I often use the following to add a bit of charm to my HTAs.

<hta:application icon="magnify.exe" />

I don't believe it's possible to use icons from a library, but just open System32 in Explorer and change it to icon view and see if there are any icons that catch your fancy at all.

This seems to be the simplest solution. Thanks. Works like a charm.
BoltBait
+3  A: 

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.

Alexandre Jasmin
Wow. Interesting idea. I will test this. Thanks!
BoltBait
I've just noticed my answer has received a second up-vote and I'd like to make it clear that while it's an interesting hack there's no guarantee that prepending a binary blob to an .hta file will work. It can break in the next version of IE, interfere with quirk-mode detection or have all sort unexpected effects. You have been warned
Alexandre Jasmin
A: 

Yess, worked. I'm so happy that now my hta looks like a real application, I also added a body script that stoos right clicking. Even if I use iframe, there is no security bar. Now just need to burn into a disc and I'm done. Wow, Microsoft is good. I like it...

Lozu
This looks like it's supposed to be a comment on another answer, (I have no idea which one), not an answer in itself.
rjmunro