During the last few weeks, we've been exploring the world of HTML Applications (HTAs), which are a Microsoft creation that promises to bridge the gap between traditional desktop applications and browser-based ones. In the last article, entitled "Mixing Scripting Languages", we saw how HTAs come with powerful capabilities that are not available to normal web pages, including database, file system, and even registry access! Now it's time to explore how to exploit some of these capabilities using VBScript. We'll be putting the rubber to the road as we roll out an HTML Application (HTA) version control strategy.
Checking for Updates
An advantage that web apps have over the traditional desktop variety is that they can check for newer versions periodically and offer automatic updates as new versions become available:
Tracking the Version Number in the Page Source
The <HTA:APPLICATION>
tag is where we can include information about the
application and its presentation. One of the attributes is the VERSION
. There
are no formatting standards for this field, but it is assumed that you would
assign a number which contains the major release number, a period, followed
by the minor release number. Here I've ascribed a typical version number of
"1.01
". We will also be using the APPLICATIONNAME
attribute to link
the version number to the application. Both these fields will be inserted at
the bottom of the page, using VBScript. We'll check for the latest version from
the website in the Window_OnLoad()
sub and insert a message in the Update <SPAN>
based on the results. Here are the contents of the page without any scripting:
Paste the above code into a new text document and save it as "HTA Version Demo.hta". Double click the new file to launch the HTML app.
There are a couple of things that bear mentioning about the above HTA.
The gradation effect in the application background is provided courtesy of
the Microsoft DXImage.Transform
control. It is just one of many eye-catching
effects that are compatible with the Microsoft Internet Explorer browser,
and by extension, HTAs! A lot of web developers are not at all familiar with
these amazing controls because they are not cross-browser compatible. Since
browser compatibility is not an issue in HTAs, why not take advantage of these
powerful effects to add some flair to your apps!
The other point of interest is the footer. It is a place holder for the application name and version number. Until we add some scripting to the page, it displays "Application Name" and "Version 0.00" for the time being.
VBScript Code
As always, the first line of code in your script should be Option Explicit
,
so that you are forced to explicitly declare all variables. We'll be needing
four constants:
- the app name
- the app version
- the root URL
- the latest version file name
Only two can be declared as constants because VBScript, like the Visual Basic language, is very strict about constants in that they can only be assigned literal values. Therefore, unlike other languages like say Java, you cannot assign a variable or expression to a constant at run-time: