Every once in a while, I discover a useful utility on the Internet. After I've used the utility for a while, I like to make sure that I'm still using the most current version. However, I don't want to have to constantly monitor the originating Web site for newer versions. One popular utility that I use extensively is McAfee's Stinger, a standalone virus-scanning tool. This effective tool's only drawback is that McAfee updates Stinger infrequently, and determining when a new version will be available is impossible.
Obviously, Stinger's release frequency depends on the number of emerging virus-attack threats. I had used the WatchThatPage site (http://www.watchthatpage.com) to monitor the Web page for changes, but I still needed a better way to learn about new versions of the file and, further, I wanted the latest version delivered to my PC mailbox automatically. Out of this desire was born my HTTPDownLoader.bat script, which you can download from the Windows Scripting Solutions Web site. (Go to http://www.winnetmag.com/windowsscripting, enter InstantDoc ID 42106 in the InstantDoc ID box, then click the 42106.zip hotlink.) Although I designed this script primarily for the Stinger utility, I've made it generic so that you can easily configure it for downloading any HTTP-available file that you need to regularly check for updates.
To download and compare Stinger versions and sizes, the script uses two new utilities that I haven't covered before. It also uses the old reliable Blat utility, which I use for sending out the email message with the file attachment.
HTTP Downloads
Although FTP file downloads are possible from the command shell, internal commands and resource kit tools don't support HTTP file downloads. Therefore, I turned to the ever-increasing number of third-party tools on the Internet and located one that you'll want to add to your list of resources. (For a listing of third-party command-shell tool resources, see the sidebar "Command-Shell Tool Resources," page 15.) The iOpus File Downloader is what I use to download the Stinger file. The iOpus File Downloader might appear to be a GUI tool when you first launch it, but it does feature command-line capability and can run without user interaction. The tool uses the following syntax for downloads:
downloader.exe -download
source destination
where source specifies the pathname of the file you want to download and destination specifies the directory in which you want to copy that file. For example, the command for Stinger might look like
downloader.exe -download
http://download.nai.com/
products/
mcafee-avert/stinger.exe
D:\stinger.exe
Note that the current version of iOpus File Downloader (which I tested) supports only a local destination directory. If you use a Universal Naming Convention (UNC) path, you'll get some unusual copy results. I pointed out this flaw in a bug report, and iOpus plans to fix the problem in a future version. For now, stick with a local path (e.g., D:\stinger.exe), then copy the file to a remote location if necessary. With HTTPDownLoader.bat file, this limitation isn't a concern.
Version Comparison
Now that you have a means for downloading the file from the Web, you need to be able to determine whether the new downloaded version differs from a previous version you might already have. For comparing file versions, I use the Windows 2000 Support Tools utility Filever, which permits comparisons of folder structures and individual files. The HTTPDownLoader.bat script downloads the current version from the Web site, then uses Filever to determine whether it matches any previous copies you already have. If the version or byte count has changed, the script sends an email message stating that the file has changed and—
if the recipient has requested it—
sends the new version as an attachment.
Here's the basic Filever command that the script uses:
filever.exe /A D:\stinger.exe
In this command, the /A switch tells the utility to not display file attributes. As the excerpt of code in Listing 1 shows, the script uses the For command to extract the version and size information. Note that I've simply combined the version (token 4) and size (token 6) information. You might ask why you need to check both version and size. First, the developer might have changed the file's content but not the file's version number. Second, you might find that the file has no version number at all or that a file's content has changed but not its size. Callout A in Listing 1 shows the comparison code. The assumption is that if the file has changed on the source Web site, it's a newer version.
Here's an important tip for using utilities inside For commands: Filever and certain other utilities might work inconsistently or incorrectly if you enclose their paths inside double quotation marks in a For command. Instead of surrounding the path in double quotes—
the typical practice for handling spaces—
you need to find a path for the utility that has no spaces. Unfortunately, the default locations for many tools, including most Microsoft tools, contain spaces. You might even have a utility that once worked fine inside a For command until you used double quotes to enclose its path, at which point you began receiving error messages such as The filename, directory name, or volume label syntax is incorrect. I always recommend that you install resource kit tools, Support Tools, and any other utilities into a folder that contains no spaces in its path (unless you want to constantly convert all your paths into 8.1 format).