The Magic of ServiceUI.exe

Recently I was working on a project to deploy a Windows 10 SCCM/MDT task sequence.  Instead of using an HTA or other front-end script to validate information, I had a series of validation steps at the start of the task sequence.  I was checking for items such as not on battery, not on wireless, not on VPN, etc.  If the check failed, a pop-up message was displayed to the installer explaining what to correct.

To perform the checks, insert a “Run Command Line” step.  In the command line, run a PowerShell script block to close the Task Sequence progress bar, perform the test, and return a Windows Shell Pop-Up message.

Below is a sample from the AC Power Check.  This check will not let the build continue until a power supply is plugged in.

powershell.exe -noprofile -executionpolicy bypass -command “(new-object -ComObject Microsoft.SMS.TsProgressUI).CloseProgressDialog(); while (!(gwmi -Class batterystatus -Namespace root\wmi).poweronline) { (new-object -ComObject wscript.shell).Popup(‘Warning: Please connect the power supply and then click OK.’,0,’Task Sequence Warning’,0x0 + 0x30)} ; Exit 0”

TS Prompt Power Supply

Check for not on VPN

Run command Line step with WMI Condition:

SELECT * FROM Win32_NetworkAdapterConfiguration WHERE IPEnabled = true and Description = “Juniper Networks Virtual Adapter”

Command Line:

powershell.exe -noprofile -windowstyle hidden -executionpolicy bypass -command (new-object -ComObject Microsoft.SMS.TsProgressUI).CloseProgressDialog() ; (new-object -ComObject wscript.shell).Popup(‘Error: This IT Managed Windows build is not supported when connected to xxx VPN. Please disconnect from the VPN and start the build again’,0,’Task Sequence Error’,0x0 + 0x30) ; Exit 96

The VPN example provided a non-zero exit code, failing the task sequence.

TS Prompt VPN

This worked great when starting a build from boot media.  The installer would know within the first 5 minutes of starting the build if it was going to fail.  However, when we started to deploy as a reload from Software Center, the user was not seeing the prompts.  This was due to the context the task sequence runs under.  The task sequence is running as the system account, and the logged in user was unable to see the messages.  I did some Internet searches and found a post about ServiceUI.exe on www.deploymentresearch.com.  Johan to the rescue again.

ServiceUI.exe is a part of the MDT toolkit.  I had to change the task sequence to run the Toolkit Package and Gather steps prior to performing the validations.

To use the ServiceUI.exe I added a call to the EXE, the process it looks for, and the full path to the PowerShell.exe file.

Now the AC Power Check is:

“%deployroot%\tools\%architecture%\ServiceUI.exe” -process:TSProgressUI.exe %windir%\System32\WindowsPowerShell\v1.0\powershell.exe -noprofile -windowstyle hidden -executionpolicy bypass -command “(new-object -ComObject Microsoft.SMS.TsProgressUI).CloseProgressDialog(); while (!(gwmi -Class batterystatus -Namespace root\wmi).poweronline) { (new-object -ComObject wscript.shell).Popup(‘Warning: Please connect the external power supply and then click OK.’,0,’Task Sequence Warning’,0x0 + 0x30)} ; Exit 0”

Now if the computer is built from boot media or as a reload from Software Center, the user is prompted if they fail any validation checks.

 

One thought on “The Magic of ServiceUI.exe

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 )

Google+ photo

You are commenting using your Google+ 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 )

Connecting to %s