Mr. Script

An HTA Reality Check

Simplify your administrative life with HTAs.

Last month we learned about the exciting world of HTML Applications, or HTAs. This month, we're going to learn more about some useful features inherent to HTAs that can help simplify your administrative life, as well as expound upon features we've already become familiar with.

Before departing on this whirlwind tour into user interface-based scripting, however, I must present one caveat: HTAs are not a panacea for all scripting ills. Rather, they're simply another tool you should keep in your scripting toolkit for use as appropriate. There are some limitations of which to be aware.

The Restrictions
First, you cannot use .WSF scripts inside HTAs. WSF scripts are XML, HTAs are HTML. This isn't so bad, as these things go, because you can still do (pretty much) anything in "standard" VBScript that you can do in a .WSF script. You lose the enhanced handling of arguments that WSFs provide, but you gain the ability to enter arguments in even more cool ways—like selecting them from lists!

Another limitation of HTAs is that the script functionality must be organized into Subs (which stands for "sub-program" or "subroutine," depending on who you ask). This can work to your benefit, however, because it forces you to adopt a more structured script writing style. Those who have been following this column for a while will remember that we discussed Subs and Functions some time ago. By breaking code down into discreet blocks of functionality, you build scripts that are more flexible and easier to understand when debugging.

But, whereas Subs must be explicitly called via the code of a "regular" script, in HTAs the Subs are event-driven. This means they just sit there and do nothing (with the exception of the Window_Onload Sub, which runs automatically when the HTA is loaded) until someone clicks a button, changes the selected item in a list or ticks a checkbox or radio button. This may seem a bit confusing at first, but you'll be surprised how quickly you get used to it.

Figure 1. HTAs allow you to verify each task completes properly before moving to the next. In this case, you can see that the database is created, then a table. Finally, data is added to the table.

So, What Can They Do?
Now that you no longer expect your HTAs to cure the common cold, let's take a look at what they do well. One thing they do very well is consolidate multiple tasks into a simple interface. To demonstrate, we're going to use the multi-step database creation script we created last October and set up each step as an individual task in the HTA.



Database Tasks

<>
ID="objDBCreate"
APPLICATIONNAME="DBCreate"
SCROLL="no"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
>


















class="button"
type="button"
value="Create Database File"
onClick="CreateDB">

class="button"
type="button"
value="Create Table"
onClick="CreateTable">

class="button"
type="button"
value="Add Data"
onClick="AddData">

Current Database:

No Database Selected






Visual Scripting—What a Concept!
In addition to combining what were originally three separate scripts, we've also given the administrator control over Database and Table names—they're no longer hardwired in the script. Note how systematic it is: You can't click the "Add Table" button until you've created a database.

Likewise, you can't click "Add Data" until you've created a table. The actual data that is written to the table is still hardwired in the script, but we'll add the capability to display and change formatted data next month (along with a few other surprises). Until then, have fun experimenting with HTAs.

More Information

Subs and Functions:
"Get Yourself Organized"

Functions not only help you organize your scripts into subroutines, they also let you choose between going global or staying local.

About the Author

Chris Brooke, MCSE, is a contributing editor for Redmond magazine and director of enterprise technology for ComponentSource. He specializes in development, integration services and network/Internet administration. Send questions or your favorite scripts to chrisb@componentsource.com.

comments powered by Disqus

Reader Comments:

Fri, Jul 7, 2006 Haripriya Nagarajan GE Global Research, NY

WScript objects work beautifully with the HTA. In other words, they are compatible apparently. I recently needed to spice up my scripts with some nice UI to make it intutive for a new user. All I needed to do was to create a UI in HTML (you know how easy it is) and my script which has several WSF objects such as Network,Shell etc worked as smoothly as it can with the HTA.

Thu, Feb 24, 2005 john germany

couldn't await the next article

Thu, Feb 3, 2005 JIm NJ

Good going Chris -
You guys at Component Source find you have been doing everything the hard way?

Now all admins will become programmers.

Seriously - HTAs have been araound for quite sometime. I'm glad to see them get some use before MS security shuts them down. I built a whol appliaction on a web server using straight DHTML and jscript. The client decided they needed it to run offline. WIth a very little bit of worked I canned it and put it on his laptop(before wireless). He would connect to the corp net (ethernet) and run the app once and it would download all of the data and persisit it to XML. When the page detected no network it would work from the XML

Add Your Comment Now:

Your Name:(optional)
Your Email:(optional)
Your Location:(optional)
Comment:
Please type the letters/numbers you see above

Redmond Tech Watch

Sign up for our newsletter.

I agree to this site's Privacy Policy.