Skip navigation

How to Learn and Even Master the Art of Writing HTAs

HTA stands for HTML Application, but it could very well stand for Hip & Trendy Application. Although HTAs have been around since Microsoft Internet Explorer (IE) 5.0, they've become increasingly popular in the past couple of years—and for good reason. HTAs offer all the features of Web pages yet they aren't subject to the same security constraints because they run as trusted applications. Plus, HTAs come with their own object model, giving them functionality (i.e., control over UI design and access to the client system) that isn't available in Web pages.

Although HTAs are a hot commodity, they might make you hot under the collar when you're trying to learn to write them. So, I'm going to highlight some resources that novice HTA writers will likely find helpful. In addition, I'll point out some resources that more advanced HTA writers can use to expand their HTA writing skills. Finally, I'll provide links to HTAs that scripters have written so that you can learn from their code.

The Basics
Before you start learning to write HTAs, you should take a look at Microsoft's “Introduction to HTML Applications (HTAs)” tutorial, which you can find on the MSDN HTML Applications Web page. The section titled "The Power of Trust: HTAs and Security" discusses the security specifics, including the fact that you need to take the same security precautions with HTAs as you would with any executable. The tutorial also has a section titled "Creating an HTA," but I don't recommend spending much time reading it. It contains little useful information.

A much better article to start with is "Hooked on HTAs." This article presents the basics, such as the HTA structure and coding elements. It also demonstrates how to create a simple input screen that has two input fields and two buttons.

The article “Use an HTA as a UI for Your VBScript Scripts” builds on the information that "Hooked on HTAs" provides by showing you how to set up more-versatile UIs. You can learn how to create UIs that feature such elements as textboxes, password boxes, single-select list boxes, multiselect list boxes, radio buttons, On Change selection combo boxes, and check boxes.

Microsoft TechNet Script Center's HTA Developers Center offers a two-part series "Creating Your Own HTAs" for novices. (Apparently, a third part will be coming eventually.) The center includes a link to the HTA Helpomatic utility. Microsoft designed this utility to lend assistance on two fronts. Besides helping you initially create an HTA by offering sample VBScript and HTML code, you can use this utility to test any modifications you make to that HTA after you've written it. The HTA Developers Center also includes links to the HTA, HTML, and Dynamic HTML (DHTML) object models. The link to the HTA reference sends you to the MSDN HTML Applications Web page, which in turn, includes links to documentation about the HTA:Application object and its various attributes/properties.

Beyond the Basics
After you have the basics behind your belt and you're ready to expand your HTA skills, check out "HTA F/X." This article discusses how to apply special effects to your HTAs. You can make cursors come alive with animation, magically change text without touching it, make text slowly fade in and fade out, make items quickly disappear and reappear, and more. The MSDN Introduction to Filters and Transitions Web page is also helpful if you want your HTAs to have a little pizzazz. This Web page explores how you can use IE's filters and transitions with basic scripting to create visually engaging and interactive documents.

The HTA Developers Center includes links to a series of six articles for the more advanced HTA writer. Those articles are

  • "Add a Gradient Background to Your HTAs"
  • "Add Color to a List Box"
  • "AutoRefresh an HTA Using a Timer"
  • "Create an HTA Without a Title Bar"
  • "Run a Script From a Text Link"
  • "Use a File Open Dialog Box to Populate a List Box (Windows XP-only)"

HTAs in Action
Sometimes it's helpful to check out HTAs that other people have written. You can see how they coded a particular task or UI feature, or you can adapt the code for your own use. Alternatively, you might want to check the following HTAs to see whether they'd be useful in your job:

  • AddColor.hta: Runs demos showing how to add color to HTA and VBScript reports as well as provides a way for you to enter color values and see the results.
  • CheckProcess.hta: Monitors crucial processes on a local or remote computer.
  • CSVviewer.hta: Lets you quickly and easily view comma-separated value (CSV) files.
  • EventLogQueryUtility.hta: Retrieves errors, warnings, and/or audit failures from the event logs on one or more computers for the specified number of days.
  • ExcelerateYourVBScripts.hta: Demonstrates how to use VBScript scripts to produce Excel reports.
  • GetADsPath.hta: Returns the ADsPath strings of Active Directory (AD) objects when you enter an object's name (CN, sAMAccountName, or GroupName attribute).
  • Install_Printer.hta: Makes installing printers on a print server easy and consistent by using the PrinterAdmin (prnadmin.dll) tool to create the printer port, share the printer, publish it to AD, and record the printer information in the printer’s properties page.
  • Install_Service.hta: Installs a script as a service so that you can run the script as a service.
  • IP Ranger.hta: Takes as input a starting IP address and an ending IP address and writes all the IP addresses within that range to a text file.
  • ReadFile.hta: Opens the specified file and displays the file's contents on the page.
  • SuperTuesday.hta: Displays the first to the fifth occurrence of any day of the week in any given month (e.g., display the fourth Monday in May) or for up to 72 months (e.g., display the fourth Monday for the next 12 months).
  • UserQuotaUtility.hta: Lets you set and display disk quotas on local and remote Windows Server 2003 and Windows XP computers.
  • Winutil.hta: Retrieves information about the local computer's startup commands, OS (including service pack data), and BIOS.

To view the code behind the HTA, you need to open the HTA in a text editor such as Notepad. Alternatively, if you have the HTA running, you can right-click and select View Source from the menu that appears.

This list of resources is by no means all-inclusive. If you know of some other helpful resources or cool HTAs, let your fellow scripters know about them in the HTML Applications (HTAs) forum on the Scripting Pro VIP Forums Web page. And if you share your favorite resource or HTA, you might be the next recipient of the "Best Post of the Month" award.

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.