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.


Comments (27)

  1. Anonymous says:

    Hi Charles,

    Are there any errors in the logs? (C:minintsmsosdosdlogs)

    Thanks,

    Ben

  2. Anonymous says:

    Hi,Guy

    I want to know how to add the icon of SkyDrive Folder to the page? :)

  3. Anonymous says:

    Kelly,

    OSD will surpress reboot requests – including the built in one. The SMS log should show that the reboot has been surpressed and that OSD will deal with it.

    If it is only this one model of machine that this error is happening on then you are going to have to work out what is unique on this versus other machines. For example are you using a different task sequence? Differnent site? SMS pacakge etc.

    Cheers,

    Richard Trusson

  4. Anonymous says:

    Thanks for the reply.

    I setup a shortcut to LiteTouch.vbs for the deployment techs to launch installation from within the OS (XP Pro and Vista).  We do not migrate any settings and completely replace the client’s machine with a fresh image.  I inserted a Partition task to fill out the rest of the refresh.

    The DeploymentType=REFRESH; SkipDeploymentType=YES commands in CustomSettings.ini work fine for BDD 2007, but do not for Windows Deployment Toolkit (the latest version).  Is there a different setting I should use to make it work?

  5. Anonymous says:

    Hi Charles,

    You can only set the deploymenttype to REFRESH if you are launching the process from within the host OS (for example XP).  

    If you are deploying using Windows PE then the deployment type should be NEWCOMPUTER.

    However you don’t need to specify this as BDD/MDT will figure it out automatically.

    Thanks,

    Ben

  6. Anonymous says:

    Hi Bob,

    This is done via the SkyDrive plug-in for Live writer.

    Thanks,

    Ben

  7. Anonymous says:

    Hi Rich,

    This is becuase that command would be part of the task sequence. It would restart and continue with the rest of the task sequence. This means that the client will still be logged in at the end of the deployment process.

    Thanks,

    Ben

  8. Anonymous says:

    Hi Dan,

    MDT still copies scripts beinging with "Z". It copies all LTI scripts and all scripts that begin with "Z".

    Thanks,

    Ben

  9. Anonymous says:

    Sorry for posting this unrelated question, but:

    I’ve been customizing the CustomSettings.ini file so all fields are filled out and hidden for our deployment techs.  One field I am having trouble with is the "Choose a Migration Type".  I entered: DeploymentType=REFRESH; SkipDeploymentType=YES.

    When I test it, nothing happens after pressing "begin" on summary page.  What is the proper syntax to autoselect "refresh" and hide that window?

    thanks,

    -Charles

  10. Anonymous says:

    Hello Dan,

    I do not see any problem as such with this approach. My preferance though is to have such things out in the open where I and others who come after me can see them.

    Putting it where you have it ‘hides’ it a bit.

    Also I think having it in the task sequence gives you more robustness – if the sequence fails before it gets there the computer reboots. My guess is that with your solution the computer reboots anyway?

    hope this helps,

    Cheers,

    Rich

  11. Anonymous says:

    Rich T,

    Thanks!  This is going to save my techs some headaches as we move closer to rolling this out to remote sites!

    Rich

  12. Anonymous says:

    Hi Kelly,

    In a ZTI/OSD deployment you are correct pop-ups are blocked. The best way to do this when, in OSD, is to use the GUI runonce command. While the OSD task sequence is running the computer is not actually logged on – it has never reached a CTRL+ALT+DEL prompt. So write your task sequence script to configure the workstation to autologon and run a restart command. Remember to either make sure autologons are set to 1 or include the restart command in another script that clears the autologon keys. Don’t put the script in the minint directory structure – that gets deleted once the task sequencer has completed.

    Hope this helps,

    Richard Trusson.

  13. Anonymous says:

    Rich,

    leave it with me and I’ll have a look into this over the next, probably, week or so.

    If you run the script/hta manually as a local admin does it work?

    Where are you running it? Post OSD completion process? Can you send me the TS.XML?

    (email deploymentguys at microsoft dot com direct – well’ try to fix this off line and post the results back here when we are done.)

    Thanks

    Richard Trusson

  14. Anonymous says:

    Hello Deployment Guys,

    Can you please help me. I have a few scripts that I’ve added to my task sequence, they do things like delete icons, disable firewall, change background image etc… nothing very complicated. The scripts work fine when running under the Admin profile but the minute I reboot and log in as a domain user some scripts seem to have run and others no!!! What am I doing wrong? My logs don’t show any errors because in fact there aren’t any errors all the scripts run in admin and all the settings are set correctly however it only seems to be working for the admin profile and not any other profile. Any help would be greatly appreciated.

    Paulo

  15. Anonymous says:

    All,

    Many thanks to Rich. We have worked on this problem again recently and managed to get it working in his environment. The trick was to copy the HTA locally and update the script so it points to the new location.

    Rich says he has it working in his XP deployments as well.

    Just shows the power of the community!

    cheers,

    Rich T

  16. Björn Axéll says:

    Hi,

    Thanks for the nice reboot function. I have noticed one problem that apear on computers with a screen resolution higher then 1024*768. On these the reboot page will be a white page and not doing a shutdown.

    Can this be changed?

    Thanks for all good tips!

  17. Rich says:

    Hi Ben,

    Why don’t we just use the restart command in MDT?  

    Thanks,

    Rich

  18. Kelly says:

    Hi Ben,

    I’m wondering how to call a final restart in a zero touch installation through the task sequence. Because you can’t have any pop ups, the shutdown /r /t 0 doesn’t work as it creates a short pop up.

    Any suggestions?

    thanks

  19. Kelly says:

    Thanks Richard.

    I’m currently experiencing 2 problems.

    1. The minint folder won’t delete at all one of of my models. Here is a log:

    Number of members in property PowerUsers to restore to group Power Users: 0 ZTIGroups 2/29/2008 12:06:04 PM 0 (0x0000)

    No groups or users to add to the "Power Users" group were specified. ZTIGroups 2/29/2008 12:06:04 PM 0 (0x0000)

    Property Groups001 is now = Administrators ZTIGroups 2/29/2008 12:06:04 PM 0 (0x0000)

    Property Groups002 is now = Power Users ZTIGroups 2/29/2008 12:06:04 PM 0 (0x0000)

    ZTIGroups COMPLETED.  Return Value = 0 ZTIGroups 2/29/2008 12:06:04 PM 0 (0x0000)

    ZTIGroups processing completed successfully. ZTIGroups 2/29/2008 12:06:04 PM 0 (0x0000)

    The task sequencer log is located at C:WINDOWSsystem32CCMLogsSMSTSLogSMSTS.LOG.  For task sequence failures, please consult this log. ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    Language/Locale Identified (in order of precedence): 1033,0409,0×0409,9,0009,0x0009 ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    Mandatory Single Application install indicated. Guid: {04d39ba3-e294-4052-800e-dbcd60589a35} ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    ################ ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    Entry: {04d39ba3-e294-4052-800e-dbcd60589a35} ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    ################ ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    Validating connection to \nbsmss1Resource$ApplicationsDelete minint folder ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    Already connected to server nbsmss1 as that is where this script is running from. ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    Change directory: \nbsmss1Resource$ApplicationsDelete minint folder ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    Run Command: \NBSMSS1SMSDISTPTSMSPKGNS10011Bbddrun.exe cscript deleteminint.vbs ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    ZTI installing application ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    About to run command: \NBSMSS1SMSDISTPTSMSPKGNS10011Bbddrun.exe cscript deleteminint.vbs ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    Return code from command = -1073741818 ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    Application Delete minint returned an unexpected return code: -1073741818 ZTIApplications 2/29/2008 12:06:05 PM 0 (0x0000)

    Property InstalledApplications001 is now = {67637afe-0fa5-4942-b88e-1a77bc59c5de} ZTIApplications 2/29/2008 12:06:06 PM 0 (0x0000)

    Property InstalledApplications002 is now = {f00169c3-cab4-49d2-a32d-87114fb71f89} ZTIApplications 2/29/2008 12:06:06 PM 0 (0x0000)

    Property InstalledApplications003 is now = {5c096037-0d11-4b44-913d-594a1823fc56} ZTIApplications 2/29/2008 12:06:06 PM 0 (0x0000)

    Property InstalledApplications004 is now = {d1981d0c-7eee-47cf-8760-f9d49d84e99c} ZTIApplications 2/29/2008 12:06:06 PM 0 (0x0000)

    Property InstalledApplications005 is now = {c05f86ef-7e9b-401d-b37e-5b1f8286d949} ZTIApplications 2/29/2008 12:06:06 PM 0 (0x0000)

    Property InstalledApplications006 is now = {3f87d8e2-a304-43aa-a2a9-4687a13afb3a} ZTIApplications 2/29/2008 12:06:06 PM 0 (0x0000)

    Property InstalledApplications007 is now = {04d39ba3-e294-4052-800e-dbcd60589a35} ZTIApplications 2/29/2008 12:06:06 PM 0 (0x0000)

    ZTIApplications processing completed successfully. ZTIApplications 2/29/2008 12:06:06 PM 0 (0x0000)

    The task sequencer log is located at C:WINDOWSsystem32CCMLogsSMSTSLogSMSTS.LOG.  For task sequence failures, please consult this log. ZTIApplications 2/29/2008 12:06:07 PM 0 (0x0000)

    Language/Locale Identified (in order of precedence): 1033,0409,0×0409,9,0009,0x0009 ZTIApplications 2/29/2008 12:06:07 PM 0 (0x0000)

    Mandatory Single Application install indicated. Guid: {d4c7c5a1-9034-4018-9f35-2d10a583ce7f} ZTIApplications 2/29/2008 12:06:07 PM 0 (0x0000)

    ################ ZTIApplications 2/29/2008 12:06:07 PM 0 (0x0000)

    Entry: {d4c7c5a1-9034-4018-9f35-2d10a583ce7f} ZTIApplications 2/29/2008 12:06:07 PM 0 (0x0000)

    ################ ZTIApplications 2/29/2008 12:06:07 PM 0 (0x0000)

    Validating connection to \nbsmss1Resource$ApplicationsFinal Restart ZTIApplications 2/29/2008 12:06:07 PM 0 (0x0000)

    Already connected to server nbsmss1 as that is where this script is running from. ZTIApplications 2/29/2008 12:06:07 PM 0 (0x0000)

    Change directory: \nbsmss1Resource$ApplicationsFinal Restart ZTIApplications 2/29/2008 12:06:07 PM 0 (0x0000)

    Run Command: \NBSMSS1SMSDISTPTSMSPKGNS10011Bbddrun.exe restart.exe ZTIApplications 2/29/2008 12:06:07 PM 0 (0x0000)

    You say that the minint folder gets deleted at the end, how should this happen? We’ve had to create a VBS script to delete it. The script works on all other models except the one in question. My guess is that the system isn’t done with the folder (still writting to it) and that’s why it’s not deleting.

    2. The built in Restart Computer command in the task sequencer doesn’t seem to work at all for a last command in the task sequence. Several of my models needs that final restart in order for all utilities/software to work properly. The Restart computer seems to work earlier in the process however, this is why I don’t understand it not working at the end.

    Thanks

  20. Rich says:

    I just tested this and the z:scriptsz-reboot.hta shows a white background and the client does not reboot.  

    This behavior seems identical to Björn Axéll’s post.  

    Any ideas on this guys?

    Rich

  21. Dan Ashby says:

    I have been using a simple delayed shutdown in unattend.xml as a synchronous task in the first logon commands sections. What do you percieve the problems to be with this?

    Thanks,

    Dan

  22. Dan Ashby says:

    Hello again. I’d like to be able to set up a custom task sequence that mimics the final stages of our MDT build that I can run on pre-built machines that have simply been joined to the domain. The intention would be for the ‘joined after build’ machines to be as similar as possible to those that are built. How can I initiate a task sequence held on the deployment server from within the full OS (vista x86 and x64 in this case)? We don’t use SCCM at present.

    Many thanks,

    Dan

  23. Dan Ashby says:

    Am I right in thinking that with MDT scripts beginning with Z no longer get copied over? As far as I can see the LTI copy scripts script just sets up an array of files to copy?

    Thanks,

    Dan

  24. Rich says:

    Deployment Guys,

    I have this working in my environment.  I’ll leave it to you to update the blog with the appropriate changes you need to make to the script and the location of the HTA file.  It is working GREAT after those two very minor changes!

    Thanks,

    Rich

  25. Fred says:

    "The trick was to copy the HTA locally and update the script so it points to the new location."

    Any chance I can get the updated scripts? I cannot get this to work properly.