HTA Forms ~ Customize Settings using an External Configuration File

The Software Inventory Tool was designed to be used at different ING locations by IBM for desktop refreshes. The Tool remotely gets a computer's Add/Remove listing, removes applications that are included in the base image, then formats the result in an Excel document. An external text file allows each site to configure information specific to their location. This article assumes the reader has some knowledge of VBScript and discusses how to read a text file, pick out information to set variables and build an array dynamically.

This HTA is just an HTML form with Javascript setting form variables and VBScript handling everything else. There is some use of WMI for remote connections and FileSystemObject for reading and writing text files. A typical Excel document built using a template, an Excel object and VBScript.

HTA in a nutshell

An HTA or HTML application is HTML code with a .hta file extension. It's a trusted application that uses mshta.exe to display the Internet Explorer object without the security restrictions of the browser.

External configuration file

Earlier versions of the Software Inventory Tool were self-contained and worked well from the Hartford site for which it was designed. The Software Exclusion List is a list of applications that are removed from the overall Add/Remove listing, which would contain many applications already installed by a base image, numerous Windows and Microsoft Updates, old device drivers, and applications or utilites installed by the user which we wouldn't be replacing.

I was asked by IBM to create single external text file that would allow easy updates to the Software Exclusion List, even though it wouldn't change from site to site, and changes to the site name and default printer path for use at other ING locations.

Figure 1. A stripped-down example of the configuration text file gives an idea of how it's organized (much like a Windows dot ini file)..

Reading the file, assigning values to global variables and building an array

The variables strSiteName, strSitePrinter and the array arrSWExclusionList are global variables and are used elsewhere in the script. After declaring some local variables in the ReadSiteConfigFile function, we first read the text file into a string strText, and then convert the string into an array arrTemp. Looking at the example text file in Figure 1, array elements 1 and 4 contain the values we need and those are assigned to strSiteName and strSitePrinter.

Next we need to cycle through each value in arrTemp looking for the tag [Software Exclusion List]. We then record the array element number of the following line and start counting the lines until we find an empty line. In the case of Figure 1, there's another section called [Not on Software Distribution], which was removed from the code listing in Figure 2 for simplification. Once again, we do the same and look for the tag, record the start point, count the number of lines till we encounter the next empty line.

In the final section, we build the arrays using the starting point arrTemp(intSWStartLine) for the number of lines that we counted intSWCount. Note the line ReDim Preserve arrSWExclusionList(i). Each time we increase the size of the array, we need to redeclare it with a ReDim. Preserve allows us to retain the existing values already in the array. Again, not shown, we do the same for arrNotInSWDist and we're done. We have 2 global string variables and 2 global arrays ready for use in other functions of our script.

Figure 2. The ReadSiteConfigFile function that reads and configures the site name, default printer and the Software Exclusion List array. (Not shown and removed for simplification are error trapping statements and code to set up a 2nd array for the Not in Software Distribution List.)