Monday, May 30, 2011

How to run a script in WinPE before MDT HTA Wizard screen pops up

Recently I've been having issues reimaging machines with a Lite Touch Image (built using MDT2010), where when I plug in the media in the machine and reboot in Winpe, instead of getting the HTA Wizard screen, I get an error that task sequence crashed (before it even started!)

A little basic background on some MDT behavior first in light of the explanation; When an LTI MDT image is applied to a machine successfully AND the machine is rebooted (ex: hit the finish button on the summary page, set the rule FinishAction=REBOOT in customsettings.ini, etc..), MDT scripts are supposed to do a cleanup of whatever task sequences, logs files, etc.. that were moved to the machine during deployment. These files are located under:
  1. C:\_SMSTaskSequence 
  2. C:\MININT 

MDT2010 does a good job cleaning most of the times (except for keeping some DLLs under C:\MININT which are totally harmless), but sometimes that's not the case. An example could be that:

  1. The task sequence crashed somewhere in the middle
  2. The deployment guy never hit the Finish button on the Final Summary page when deployment ended. 

And so, when trying to reapply the image and the machine is booted into WinPE, it picks up whatever task sequence found under C:\_SMSTaskSequence or C:\Minint.

After hours of research trying to figure out a way to clean those folders, I came across this simple solution:
  1. Mount WinPE image file from E:\content\boot\LiteTouchPE_x86.wim (where E is the media drive letter)
  2. Create a batch script to delete the folders (ex: RMDIR /S /Q C:\_SMSTaskSequence) and place it under %MOUNTDIR%\Windows\system32\ 
  3. Open %MOUNTDIR%\Windows\System32\winpeshl.ini and add the command to launch the custom script before bddrun.exe. An example of the ini contents are as below:
  4. Unmount the wim

That's all!  

Note that everytime you regenerate the media the wim file will be replaced with the default one from MDT and the above steps will have to be redone.

No comments:

Post a Comment