In my previous blog entry, I explained my customer’s need for stand-alone USMT Capture and USMT Restore task sequences and their need for a notification box to pop up and let the technicians know the process completed successfully.  This post will continue in that vein and discuss the notification HTA for the USMT Restore task sequence.

The requirement was to make a notification box pop up and pause the task sequence until it is acknowledged or closed. 

I created a simple HTA that will look for the loadstate.log in the CCM\Logs\SMSTSlog folder based on architecture.  As I am sure you are aware, the SMSTSLog folder is where the logs are placed during the task sequence, so they are always guaranteed to be current.  It isn’t until the task sequence is closed out that the logs are moved one level up and the SMSTSLog folder removed.

If they are running on a Windows XP machine the path is:


If they are running on a Windows 7 x64 machine, the path is:



The HTA then parses this log file looking for ‘MIGACTIVITY_SUCCESS’.  If this message exists in the log file, the HTA returns the following box…



If it doesn’t exist, they see the following box…



Now that the HTA is functional, I have to put it in the task sequence and make it visible while running inside the full operating system.  This is where the fun really begins…

Luckily, we can take advantage of ServiceUi.exe that exists in the Tools\x86 or Tools\x64 folders within the Microsoft Deployment Toolkit package.  We can launch this by calling it from %toolroot%.

Placing my HTA file in a folder called CustomScripts underneath the Scripts folder in the toolkit package allows me to use the command line…

%toolroot%\serviceui.exe –process:tsprogressui.exe %systemroot%\system32\mshta.exe %scriptroot%\CustomScripts\USMTRestoreStatus.hta

Here is an example of how to call my HTA using the ServiceUi.exe…





For more information on the use of ServiceUI.exe, see ‘Can I use ServiceUI.exe to launch other programs besides the UDI Setup Wizard?’ on Cameron’s Blog – Cravings of System Center.



< head>
< title>USMT Restore Status</title>
< /head>

<script language="VBScript">

' *****************
' * Window_OnLoad *
' *****************

Sub Window_OnLoad
  'This method will be called when the application loads
   window.resizeTo 600,300
   window.moveto 1,1
End Sub

' *****************
' * USMTStatus    *
' *****************

Sub USMTStatus
Const ForReading = 1

' Set the search parameter
Set objRegEx = CreateObject("VBScript.RegExp")

' Prepare log file connectivity
Set objFSO = CreateObject("Scripting.FileSystemObject")

' WMI Connectivity
strComputer = "."
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2")

' Query WMI for processor architecture type
Set colProcessors= objWMIService.ExecQuery ("Select * From Win32_Processor")

' Set log file location based on processor architecture type
For Each objProcessor in colProcessors
  If objProcessor.Architecture = 0 Then
      Set objFile = objFSO.OpenTextFile("C:\windows\system32\ccm\logs\SMSTSLog\loadstate.log", ForReading)
      Set objFile = objFSO.OpenTextFile("C:\windows\syswow64\ccm\logs\SMSTSLog\loadstate.log", ForReading)
  End If

' Set initial returnSuccess to 'False'
returnSuccess = False

' Parse the scanstate.log file for search parameters
Do Until objFile.AtEndOfStream
    strSearchString = objFile.ReadLine
    Set colMatches = objRegEx.Execute(strSearchString) 
    If colMatches.Count > 0 Then
        For Each strMatch in colMatches
            returnSuccess = True
    End If

' Set HTA pop-up box text based on search results
If returnSuccess = True Then
    DataArea.InnerHTML = "The user state was SUCCESSFULLY restored.<br><br>PLEASE CLOSE THIS BOX TO END THE TASK SEQUENCE."
    DataArea.InnerHTML = "The user state was NOT SUCCESSFULLY restored.<br><br>PLEASE CLOSE THIS BOX TO END THE TASK SEQUENCE."
End If



End Sub   


< /script>

<body bgcolor= "white">

<span id = "DataArea"> </span>

<!--{{InsertControlsHere}}-Do not remove this line-->

< /html>



This post was contributed by Brad Tucker, a Senior Consultant with Microsoft Services, East Region, United States

Disclaimer: The information on this site is provided "AS IS" with no warranties, confers no rights, and is not supported by the authors or Microsoft Corporation. Use of included script samples are subject to the terms specified in the Terms of Use