I needed a quick way to run a script after certain task sequences. MDT doesn’t really have a way to do this after everything completely finishes. I took my own approach, being a programmer I did modify litetouch.wsf.

Here’s what I did, for anyone interested. Open up litetouch.wsf in the deployment share scripts directory,  find the line “Process the finish action” and immediately above it, enter this code which I have in mine:

'vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
 'MM: FINISHING SCRIPT

 Dim mm_WshShell
 Dim mm_filesys

 Set mm_WshShell = WScript.CreateObject("WScript.Shell")
 Set mm_filesys = CreateObject("Scripting.FileSystemObject")

 If mm_filesys.FileExists("c:\Windows\MM_Finish.exe") Then
 mm_WshShell.Run "c:\Windows\MM_Finish.exe", 0, true
 End If

 'MM: /FINISHING SCRIPT
 '^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Note that in this instance, if it finds “c:\Windows\MM_Finish.exe” it will run the file (and wait for it to complete). An easy way to get this file there is to create an application install that moves the file over, then put an install application task into the sequence.

Done! I prefer this way as this happens at the very end.

Comments 8

  • Will this also run .bat files? Sorry I am not much of a programmer. Just trying to get this to work.
    I have a WSUS server that I am using for deployment. We don’t want the users to use this server as they are mostly remote and over seas. So we want them to just get there updates from Microsoft. So I got the MDT 2010 to use the WSUS server during deployment and that is working fine. But it then puts in a registry key that points it to the WSUS server. So to remove the registry key I wrote a .bat file. But you have to run the bat file manually. And I would like to get it to run at then end of deployment.
    I have tried the following below code in my litetouch.wsf but it does not seem to work. Just wondering if the code only works for .exe or will it work for .bat files but I am just missing something.

    iRetVal = Failure

    End if
    ‘MM: FINISHING SCRIPT

    Dim mm_WshShell
    Dim mm_filesys

    Set mm_WshShell = WScript.CreateObject(“WScript.Shell”)
    Set mm_filesys = CreateObject(“Scripting.FileSystemObject”)

    If mm_filesys.FileExists(“c:\Windows\removeWSUS.bat”) Then
    mm_WshShell.Run “c:\Windows\removeWSUS.bat”, 0, true
    End If

    ‘MM: /FINISHING SCRIPT

    ‘ Process the finish action

  • First off, this might not be something you need to run at the VERY end of the script. It might be easier to just add this registry fix as a program in the MDT interface, then add the ‘Install Application’ task sequence near the end of the tasks. I would try this first.

    If they change this at a point where the above is impossible, then I would use my script. Keep in mind that if you are using a boot CD the boot media MUST be remade and new CD must be made (litetouch.vbs exists on the CD, updating it without burning it will only have it work with people running it via the network.

    If you are running it over the network/did burn a new CD the code looks correct, and bat files should also work. One thing to test it would be to copy that code (minus iRetval at the top) to a VBS file, and run it alone, and just make sure it runs your batch file.

  • Thank you so much for pointing me in the right direction. I added a registry fix with the ‘Install Application’ and moved it to the end of the task sequence and it worked like a charm. :) Thanks a ton for your help.

  • “An easy way to get this file there is to create an application install that moves the file over, then put an install application task into the sequence.”

    Could you show the parameters of the application install and the install application task in the task sequence?

  • Hi Fred,

    To clarify, you would make a new application. This application would reside in, say: ‘\MyApp’ and would be ‘Runme.bat’. You would then make a second file in the \MyApp application dir. This can be anything that you’d want the installation to run at the very end. We could call it finish.bat. Copy.bat would do nothing more than ‘copy .\finish.bat %windir%\finish.bat’ for example.

    The application would be all set up. Then you would have to go in and modify the task for the Windows install to add a sequence ‘Install application’ and put it in somewhere that works (perhaps just after the driver installs, for example). Just select the MyApp application and you are good to go.

    Sorry if not clear enough! I am not next to my MDT server.

  • Hi Mike,

    I’m currently setting up a LTI Infrastructure which deploys MOC’s. These are images which have virtual machine files loaded in the C:\Program Files\Microsoft Learning\ folder.

    The only thing left to do is import the VM’s into Hyper-V. I have a script that does exactly that, and works when I run it manually.

    I tried implementing this script to run after the MDT completes an install. First by having it as a part of the task sequence. This had it run, but it didn’t seem to complete, that is, it wouldn’t actually import the machines, it only created the symlinks.

    Second I tried your method above, this didn’t run at all.

    I had the file run this “C:\Program Files\Microsoft Learning\Scripts\start.cmd”

    That is a .cmd file that starts a powershell script.

    Still no juice.

    Any suggestions?

  • Best bet would be to add a line to that piece of code which writes to the log, so you can at least see if the code is bring run through. I would definitely start there if you need to troubleshoot why this code isn’t being run.

    I’m not sure if I’d work on that first considering that your code being run by the task sequence likely wouldn’t work if it is not already working in the task sequence. One thing to consider, is LTI running as a different elevated user than the one you use when you run the script?

  • Hi !
    Is that what you think is good code ?

    ‘ Enable TaskMgr if it was disabled during the task sequence

    if UCase(sDisableDiskMgr) = “YES” then
    oShell.RegWrite “HKCU\Software\Microsoft\Windows\CurrentVersion\Policies\System\DisableTaskMgr”, 0, “REG_DWORD”
    End if

    Dim mm_WshShell
    Dim mm_filesys

    Set mm_WshShell = WScript.CreateObject(“WScript.Shell”)
    Set mm_filesys = CreateObject(“Scripting.FileSystemObject”)

    If mm_filesys.FileExists(“c:\Windows\notepad.exe”) Then
    mm_WshShell.Run “c:\Windows\notepad.exe”, 0, true
    End If

    ‘ Process the finish action

    Select Case UCase(sFinishAction)
    Case “SHUTDOWN”
    Shutdown
    Case “RESTART”, “REBOOT”
    Reboot
    Case “LOGOFF”
    Logoff
    End Select
    thanks a lot

Leave a Reply

Your email address will not be published. Required fields are marked *