HTA in SCCM Task Sequence

Summary

There has been lots of discussion about using Microsoft HTA (HTML Applications) files to prompt for user input, pop up notifications, and so on, in a ConfigMgr OSD Task Sequence. Although, by default, the task sequence engine prevents interactive programs from being seen, you can work around this functionality by simply writing a VBscript wrapper around the program you want to make visible.

WinPE

In order to use HTAs in your task sequence during the WinPE phase, you’ll need to make sure that you have HTA support built into your WinPE 2.0 boot image. This may require building a custom boot image using the Windows AIK, adding HTA support, and then importing it into your ConfigMgr console.

VBscript Code

To restate what I said earlier, in order to spawn an HTA interactively during a task sequence, all you have to do is wrap the MSHTA command into a VBscript. This assumes that you have already developed your own HTA called “MyHTA.hta” … Let’s take a look at how to do this:

' Create a WshShell object
set sh = CreateObject("Wscript.Shell")
' Call the Run method, and pass your command to it (eg. "mshta.exe MyHTA.hta").
'
The last parameter ensures that the VBscript does not proceed / terminate until the mshta process is closed.
call sh.Run("mshta.exe MyHTA.hta", 1, True)

Packaging It Up

  1. Put your HTA and VBscript (we’ll assume it’s called SpawnHta.vbs) inside a standard ConfigMgr package
  2. Add a “Run Command Line” task sequence item into your task sequence, where you’d like the HTA to appear
  3. In the command line box, type “cscript SpawnHta.vbs
  4. Check the Package checkbox, and click Browse to locate the package you created

You have now successfully added your HTA to your task sequence! Here is a screenshot of what my task sequence looks like (my script sits in a subfolder of the package, and is named differently):

HTA Prompt

One Step Further: Hiding the Task Sequence Progress UI

Although the above VBscript code will spawn the HTA window interactively, you’ll still probably be disappointed that the task sequence progress UI window is set to be “always on top” meaning that you’ll have to manually move it out of the way to fully see the HTA. I have a little trick though, which lets you hide this, and bring it back, exactly to where it was …. automatically! Download and install AutoIT, and compile the following script:

dim $WindowName
dim $winpos
dim $winstate
dim $WindowWait
; Partial title of task sequence progress window
$WindowName = "Installation"
; Store current position of task sequence progress window
$winpos = WinGetPos($WindowName)
; Move the task sequence progress window way off-screen
if WinExists($WindowName) Then
 WinSetOnTop($WindowName,"",1)
 WinActivate($WindowName)
 WinMove($WindowName,"",10000,10000)
EndIf
; Give the hosting VBscript a couple of seconds to spawn off mshta.exe
Sleep(2000)
; Wait for mshta.exe to close
ProcessWaitClose("mshta.exe")
; Move the task sequence progress window back to its original position
if WinExists($WindowName) Then
 WinSetOnTop($WindowName,"",1)
 WinActivate($WindowName)
 WinMove($WindowName,"",$WinPos[0],$WinPos[1])
EndIf

  1. Place the compiled executable into the same folder where your VBscript and HTA reside
  2. Update your VBscript to look like this:

Option Explicit
dim sh, fso, scriptpath, ToolsFolder, HideUiExe
set sh = CreateObject("Wscript.Shell")
set fso = CreateObject("Scripting.FileSystemObject")
scriptpath = left(wscript.scriptfullname, len(wscript.scriptfullname) - len(wscript.scriptname))
ToolsFolder = sh.ExpandEnvironmentStrings("%SYSTEMDRIVE%\Tools\")
HideUiExe = ToolsFolder & "HideTSUI.exe"
If Not fso.FolderExists(ToolsFolder) Then
  call fso.CreateFolder(ToolsFolder)
End If
' *** Copy HideTSUI exe locally, otherwise the Windows Script Host
' *** can't find the file ... kind of weird, but oh well
If Not fso.FileExists(HideUiExe) Then
  call fso.CopyFile(ScriptPath & "HideTSUI.exe", ToolsFolder)
End If
dim Result, HtaCmd
wscript.echo "Hiding user interface (" & HideUiExe & ")"
Result = sh.run(HideUiExe, 1, false)
wscript.echo "Spawning HTA (" & HtaCmd & ")"
HtaCmd = "mshta """ & scriptpath & "OSPrompt.hta"""
Result = sh.run(HtaCmd, 1, true)

Conclusion

Once you’ve followed these directions, you should be able to spawn an interactive process during a ConfigMgr OSD task sequence! Please feel free to leave a comment or e-mail me if you have any trouble with this!