//
you're reading...
MDT, SCCM, VB Script, Windows

How to control progress bar in MDT/SCCM Task Sequence using VBScript

Ever wondered how to control Task Sequence progress bar? This post will give you a quick overview on how to tap in to relevant object with an example of custom delay step. This approach works just fine in both MDT and SCCM Task Sequences without modifying a single line of code!

mdt_progress_bar_2

Controlling the progress bar is fairly easy, however it may prove to be a bit confusing to begin with. First of all, you need to create a Microsoft.SMS.TSProgressUI object – this will give you a handle to manage the progress bar. Second of all, you need to create a Microsoft.SMS.TSEnvironment object – this will give you the ability to read Task Sequence variables for clarity and consistent look with remaining steps of the Task Sequence. Lastly, you need to call ShowActionProgress method to bring it all together! You can find the Microsoft reference page here: https://msdn.microsoft.com/en-us/library/cc145940.aspx

HRESULT ShowActionProgress(
 BSTR pszOrgName,
 BSTR pszTaskSequenceName,
 BSTR pszCustomTitle,
 BSTR pszCurrentAction,
 ULONG uStep,
 ULONG uMaxStep,
 BSTR pszActionExecInfo,
 ULONG uActionExecStep,
 ULONG uActionExecMaxStep
);

MSDN page gives you detailed explanation on each of the parameters, however here is a quick cheat-sheet showing which Task Sequence variable ties with given parameter and what it translates to in the screen shot above.

  • pszOrgName – organization name as defined by _SMSTSOrgName. “slightlyovercomplicated.com” in the above example
  • pszTaskSequenceName – Task Sequence name as defined by _SMSTSPackageName. “Lite Touch Installation” in the above example
  • pszCustomTitle – progress window title as defined by _SMSTSCurrentActionName. “Installation Progress” in the above example
  • pszCurrentAction – name of the Task Sequence step being executed as per _SMSTSCurrentActionName. “Wait application” in the above example
  • uStep – the current Task Sequence step number as defined by _SMSTSNextInstructionPointer. Takes part in working out progress displayed in the TOP progress bar
  • uMaxStep – overall number of steps in the Task Sequence. Takes part in working out progress displayed in the TOP progress bar
  • pszActionExecInfo – your custom text displayed above bottom progress bar. “Time reamining: 24 seconds…” in the above example
  • uActionExecStep – your custom numerical step number within total number of custom steps. Takes part in working out progress displayed in the BOTTOM progress bar.
  • uActionExecStep – your custom numerical total number of steps. Takes part in working out progress displayed in the BOTTOM progress bar.

To re-cap, all you really need to worry about are the last three parameters. I would recommend leaving remaining parameters tied with their appropriate variables to ensure consistency with Task Sequence steps you are not handling yourself. Please note that you may find that some of the parameters may be ignored, depending on MDT/SCCM Task Sequence engine driving your deployment.

That’s enough talk, now you probably just want to see the code and bring it to action. Below is a simple VBScript that introduces user-defined delay to the Task Sequence (or 60 seconds delay if not supplied as argument to the script). It moves bottom progress bar as the time passes, and also displays in “real time” how many seconds are left until timeout is reached.

Option Explicit

' Declare variables
Dim objArgs, objProgress, objTSEnv
Dim iTimeout, iStep, uStep, uMaxStep
Dim strCustomMessage

' Get script argument
Set objArgs = Wscript.Arguments.Named

' Assign custom timeout value or use default of 60 seconds
If objArgs.Exists("timeout") Then
  iTimeout = CLng(objArgs.Item("timeout"))
Else
  iTimeout = 60
End If

' Create a handle to Task Sequence object
Set objTSEnv = CreateObject("Microsoft.SMS.TSEnvironment")

' Get Task Sequence step numbers (current and overall)
uStep = CLng(objTSEnv("_SMSTSNextInstructionPointer"))
uMaxStep = CLng(objTSEnv("_SMSTSInstructionTableSize"))

' Create a handle to Progress window object
Set objProgress = CreateObject("Microsoft.SMS.TSProgressUI")

' Run through a loop
For iStep = 0 to iTimeout
  ' Create custom message
  strCustomMessage = "Time remaining: " & iTimeout - iStep & " seconds..."

  ' Update progress window with custom data
  Call objProgress.ShowActionProgress(objTSEnv("_SMSTSOrgName"), objTSEnv("_SMSTSPackageName"), objTSEnv("_SMSTSCustomProgressDialogMessage"), objTSEnv("_SMSTSCurrentActionName"), (uStep), (uMaxStep), strCustomMessage, (iStep), (iTimeout))
  ' 1 second delay
  Wscript.Sleep(1000)
Next

Discussion

4 thoughts on “How to control progress bar in MDT/SCCM Task Sequence using VBScript

  1. Thanks, Mietek, for this wonderful article! But I am a little bit lost, where do I put this script in order to work? I’m using MDT and if I put it in the script-root folder I don’t know where to call it from (customsettings.ini?)

    Like

    Posted by Michael | 2017-12-13, 09:26
    • Hi Michael, I am glad you enjoyed the article. Just put your VB script in the “Scripts” folder of your MDT share and call it in your Task Sequence using Run Command Line step. The command to run is: cscript.exe %SCRIPTROOT%\your_script.vbs
      Alternatively you could leverage %DEPLOYROOT% variable – same methodology applies, just point the command line to a specific package in your Applications directory, e.g.: cscript.exe %DEPLOYROOT%\Applications\CustomScript\your_script.vbs

      Like

      Posted by Mietek Rogala | 2017-12-13, 10:15
      • Hi Mietek,
        Great post !
        I have been trying to achieve the above from a long time.
        Could you tell me how can I make it work please.
        I have copied the script and placed it in the scripts folder but completely lost in what to do now.
        I have created TS just before Install operating system but what happens is , window shows up counting down from 60s ?
        What should I do to have a nice timer counting down the installation process ?

        Thanks.

        Like

        Posted by Sebastian | 2018-03-23, 23:06

Trackbacks/Pingbacks

  1. Pingback: How to downgrade TPM 2.0 to TPM 1.2 on HP machines in SCCM OSD Task Sequence | Slightly Overcomplicated - 2017-08-01

Leave a comment

Categories