Friday, February 29, 2008

Unchain Your ".hta" Extension!

I'll try to aid you to a solution of an error I've come up with during the creation of an .hta application. So keep on reading, for which you might find a solution to yours that you've never thought would be relevant.


For Newbies:
What is an .hta application? How does it work?

Basically, it is an html page with the priveleges of running real applications. You can make the .hta files do several things using VBScript. And the best part is: the design is almost just about html coding!
You might think that some users with bad intentions (a.k.a. lamers) could create web pages using .hta and spread their viruses all around, but thats totally wrong. These files are not actually run directly by your web browser, so you're safe!


The Problem & The Mild Solution:
While editing the autorun.hta file of our product Infraskope's Setup CD, I've come up with a weird error message. Here is the whole story:

Infraskope is a product that is made up of several components. So you have to go through several setup files to complete your installation on the main server. Our aim was to create such an .hta application that by a single click on the "Install" link/button it would go through the setup process by itself, one by one and in given order. Not a silent intallation of course, but more like an automated installation ordering the setup files to run one after another.

I've edited the previous .hta file we used and added some lines of code to run an application. Later, when I tried to run and test the file, I've came up with such a message after clicking on the Install button:
I've decided to try the file on another computer and the error message did not come up. So I knew the codes were clean but there was something weird going on in my computer. I made a comparison between my computer and the one that ran the file with no errors and noticed that my computer gave me a security warning before running the hta files and the other one did not.

Whenever an .hta files is to be run, my computer gave me this warning:

Do you want to run or save this file?


That was not supposed to be asked! If you take another look at the first image, you will see that it gives the error message for itself. It says it cannot find itself! So while searching, I've found out that the hta files were actually handled by a file called mshta.exe (which I think is based on IE), but my computer tried to run the .hta application directly by Internet Explorer. And for the security reasons (the previously mentioned lamers spreading virus scenario) IE is not allowed to run the .hta files without your permission. So here is what happened roughly:
1) I double clicked the autorun.hta file.
2) It asked for my permission to run it.
3) I clicked on the install button.
4) The .hta application tried to run the program I linked in the codes but could not get the permission from IE so gave the error message.

After finding this out, the solution was pretty much easy. I right clicked on a random .hta file, selected Open With -> Choose Program. Clicked on Browse and located the mshta.exe file in ...\Windows\System32\. Before clicking OK and running the file, I selected the "Always use the selected program to open this kind of file" checkbox.
Bingo! It all went back to normal... I hope that helped.

2 comments:

  1. Thanks for this article.. it really helped me out !

    ReplyDelete
  2. Thanks! mshta.exe is the way to go.

    ReplyDelete