Acronym soup time. For the past 3 weeks I've been working in Edinburgh attempting to write a user friendly menu program for a major company's build process. The company uses WinPE, a stripped down version of Windows XP which allows users interaction. Eventually the process hands off to SMS which installs the operating system and the ancillary applications.
The requirement for the menu program was a wizard like system which prompts the user for the build requirements, pulling the options from a database and then writes a single record to a database. Simple enough, even when constrained to an HTA; at least until you try it under WinPE. Under "normal" circumstances when you create any ADO objects the ADO framework will check where it is running. If it's running in a scripting environment, such as WSH everything works without a hitch, if it's running an HTA it will use IE's trust/zone/security model to check if it should create itself. Again this is not a problem, if you're running under a normal OS, but as soon as you try to run it under PE everything fails, WinPE simply doesn't support IE's trust model.
So what can you do to make ADO work inside HTAs under WinPE? You cheat. You may have noticed the small hint in the previous paragraph, ADO will work in scripts. What I ended up doing is call out to a Windows Scripting file from within the HTA to do all my database work. The script file makes the connection, executes the stored procedures and then enumerates over the resultant recordset, saving it to a text file which is then read within the HTA and processed. In order to do this I need to be able to execute a command line, this is done using the WshShell object's run method;
Set WshShell = _
WScript.CreateObject("WScript.Shell")
WshShell.Run _
"cscript //nologo //job:GetDatabaseOptions", _
0, _
true
The optional parameters on the Run method hide the command shell window and wait until the command has finished executing before continuing.
Now can I go back to C# please? I found myself putting semicolons onto the end of lines and forgetting that If statements need a Then in VBScript ....
Admittedly this is a kludge and my feedback has made its way to Redmond along with my incredulity that the Vista PE environment does not support ADO in HTAs either. Obviously you can (and should) create a subroutine within the HTA to perform the heavy lifting, calling out to the Windows Scripting file with all the common parameters, and reading the resultant file (in my case pipe delimited) back in again which will make your life easier when making multiple database calls.