Jump to page content

Bug of the moment 2010-06-03

As fate would have it, it has become necessary for me to obtain the 2007 Microsoft Office OPK Master Kit. For English, this is a 2 GB download from Microsoft’s partner website, which Firefox estimated at up to 24 hours to complete!

To aid in downloading it, the download page offers you the BITS Internet Explorer Plug-in that uses the Background Intelligent Transfer Service in Windows to provide full resuming download support. There doesn’t appear to be an official download page for this tool or any other acknowledgement of its existence; it would appear that someone with a kind (or sadistic) heart deep in the bowels of Redmond threw it up in exasperation of Internet Explorer for Windows still not having a download manager with resume capability like the Macintosh port had a decade ago:

That said, after battling with it for a while, I decided to use Mozilla Firefox (3.6.3 I think, if my home computer is anything to go by) which resumed perfectly during testing … and failed miserably when the inevitable glitch occurred. Obviously I was never going to complete the download that way.

I returned to BITE (I’ll call it that for short) but couldn’t for the life of me get it to do anything. After running install.js, the promised menu item was added to the context menu:

However, the menu item did nothing. I dug out a copy of bitsadmin.exe (which F-Secure Client Security had previously renamed bitsadmin.0xe, cheers mate) to verify that I wasn’t already running three dozen instances of the download in the background. Giving up on BITE, I taught myself how to manually queue and start the transfer using the command-line bitsadmin.exe tool, raise the priority to foreground, and enable interactive monitoring of the transfer queue.

Taking another look at BITE though, I turned up a few interesting anomalies. For starters, it uses a PKSFX command-line self-extractor, something I never imagined I would see again, having set aside my 486 in 2000:

M:\Desktop\BITS\Extract>bitsfiles.exe PKSFX(R) Version 2.50 FAST! Self Extract Utility for Windows 95/NT 4-15-1998 Copyright 1989-1998 PKWARE Inc. All Rights Reserved. Registered Version PKZIP Reg. U.S. Pat. and Tm. Off. Extracting files from .ZIP: M:/Desktop/BITS/Extract/bitsfiles.exe Inflating: uninstall.js Inflating: bits_ie.exe Inflating: bits_ie.htm Inflating: install.js Inflating: readme.htm

The problem with the installer lies in this code snippet from install.js:

function install(Dir, RunURL) { //WScript.Echo("Copying files..."); WshShell.Run("%COMSPEC% /c \"copy bits_ie.htm "+Dir+" /Y\"",1,true); WshShell.Run("%COMSPEC% /c \"copy bits_ie.exe "+Dir+" /Y\"",1,true); ... }

If you look closely, code that otherwise relies on ActiveX scripting is starting up the command prompt to copy files! The code even makes use of class FileSystemObject elsewhere, yet still uses the command prompt to create directories:

var fso = WScript.CreateObject("Scripting.FileSystemObject"); ... //If file missing in system directory if (!(fso.FileExists(sDir+"bits_ie.exe"))) { try { if (sSystemDrive.length = 0) { sSystemDrive = "C:"; } WshShell.Run("%COMSPEC% /c \"md "+sSystemDrive+"\\BITS_Plugin\"",1,true); ...

This would appear to be a stupid but otherwise harmless mistake, except for users whose desktop is operating under folder redirection. I am deeply disappointed by Microsoft’s continual failure and refusal to allow the command prompt to take a UNC path as the working directory. In this instance, with the installer on the desktop, the command prompt can’t inherit the working directory of the install script, so it cannot find any files to copy. (silvestrij notes that you can use %~d0%~p0 in a batch file to obtain the working directory even when it’s a UNC path.) Simply copying via FileSystemObject resolves the problem immediately.

Of course, even this would have been more readily tracked down had Microsoft not made two other mistakes. Firstly, they refer to BITE as a “plug-in” when it isn’t. It simply makes use of a facility in Internet Explorer where you can add a custom menu item that passes the URL of a link as a parameter to another address. In this case, it passes it to bits_ie.htm on your hard drive which uses JScript within a <script> tag to locate and launch bits_ie.exe via ActiveX file system scripting. (While I was at it, I added an unescape() to this page so that any downloads do at least get the address unescaped correctly when deriving a filename. Amazing how many people don’t get that right.)

Should bits_ie.htm itself not exist at the location defined in the Registry (at HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\MenuExt\Background Download As), Internet Explorer doesn’t raise an error, instead it silently eats the command. Had it complained that bits_ie.htm wasn’t found and where it expected it to be, I would have immediately spotted that the C:\Program Files\BITS_Plugin directory was empty and figured out that the installer was duff. (Also note that it writes to HKEY_CURRENT_USER but installs the plugin to whichever of %WINDIR%\System32 or C:\Program Files\BITS_Plugin doesn’t raise an exception.)

I could have used wget here. The actual download doesn’t verify that you are logged into Microsoft’s website; you simply have to log in to obtain the download address. This becomes clear when you realise that BITE–being not a plugin at all–doesn’t operate on browser state the way DownThemAll! does in Firefox. Had I realised this, I would have just used wget, although I did have a pretty good idea after manually creating a background job with BITS and observing that it didn’t fail.

I guess that the sad part of this story is that Microsoft were unable to recommend a single quality tool from their arsenal and instead suggested some old demo program instead, without any due care or testing. Though I say “old” with reservation because, although they forgot to include a VERSIONINFO resource, they did remember to include a 48×48 pixel icon, which is more than I can say for much of Windows XP!

Posted 3rd June 2010 – Comments and questions?