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!


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"))
  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


No comments yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: