BDD 2007: Rebooting at the end of the Task Sequence

An oft asked question is how do I reboot a computer at the end of the Task Sequence in BDD 2007 LiteTouch? One of the more popular answers is to edit the LiteTouch.wsf file. I must admit I am not a fan of 'hidden' reboots nor of editing the core BDD scripts if I can help it. Were it up to me no task (in the task sequence you can select reboot after this task has run), MSI or Package would be allowed to reboot the system. All reboots should be out in the open where they can be properly controlled - i.e. in a named task that only reboots the system. This allows the grouping of actions to get the least number of reboots and the fastest build. So how do I reboot a computer?

I use one of two ways. There is the dirty indeterminate way or the more elegant cleaner deterministic way.

The 'Dirty' way.

One of the, if not the, last task you would have in your task list is a delayed reboot command. I use shutdown.exe to accomplish this. Create a new task, I suggest, called "Delayed Reboot" that has the following command line;

shutdown.exe /f /r /t 60

This forces (/f) the computer to restart (/r) in sixty seconds (/t 60). The problem with this is that if the termination of the task list, and cleaning up of the MIININT directory, takes too long the computer is left in an unknown state. I told you it was dirty. However it has the advantage of being easy and quick to implement.

The 'Clean' way.

The clean way is a little more complex but still uses shutdown.exe. Briefly this way launches a vbscript that launches an HTA that monitors the task list process (TSManager.exe) When it can not find any running instances of TSManager.exe it forces a restart of the computer. Feedback is presented to the user telling them that the computer is about to restart and then down it goes. By monitoring to find out when the processes ends this process is a little cleaner - so long as the Task Sequencer is running the restart is paused - indefinitely.

This approach actually needs two (yes two!) scripts to work. We need to use one script to call the monitoring script and the monitoring script itself. Once the monitoring script has started control is returned to the Task Sequencer. Remember if we don't return control the Task Sequencer will never end and the computer will never restart. The monitoring script watches for the termination of the Task Sequence processes. It checks every 20s using the 'window.interval' function. This is akin to vbscripts sleep function. Once it notices that there are no Task Sequencer processes running it calls shutdown.exe with a time delay, just to make sure everything has really been cleaned up. I could have the time delay in the script and call shutdown without one. Putting the delay in shutdown makes it marginally harder for an end user to cancel the restart (shutdown.exe /a) than it is to stop a script.

To implement this complete the following steps.

Copy the scripts in the linked ZIP to the scripts directory on your BDD server.

At the end of the Task Sequence create a task and enter the following text as the command line;

cscript.exe "%SCRIPTROOT%\z-reboot.wsf"

Update your deployment point(s) and try a test build.

Currently when shutdown.exe is called it delays firing the reboot for 60 seconds. This can be changed if required but gives you a reasonable comfort zone for dev and test purposes. The command is held in the z-reboot.hta file.

The files can be downloaded from my Live Drive folder.

Note The second script does not log any information to the BDD logs. The logs should have been cleaned up by the termination of LiteTouch and the required script (ZTIUtility.wsf) that holds the functions to write to the logs has similarly been removed.

 

This post was contributed by Richard Trusson a Senior Consultant with Microsoft Services UK.