Building application with a purpose of being used in a Task Sequence in ConfigMgr can be accomplished with various methods in different languages. Recently, I’ve started to explore C# and built a couple of applications meant for configuring the task sequence environment. If you for instance are building an application (e.g. a front end) and want to hide the progress UI, run your application and then resume the task sequence from the last instruction, the following code snippets can be handy and hopefully point you in the right direction for your project (shout out to Johan Schrevelius that got me started with loading the ComObject in the first place).

Hide Task Sequence

public static void CloseTSProgressUI()
{
	Type tsProgress = Type.GetTypeFromProgID("Microsoft.SMS.TSProgressUI");
	dynamic comObject = Activator.CreateInstance(tsProgress);

	comObject.CloseProgressDialog();

	if (System.Runtime.InteropServices.Marshal.IsComObject(comObject) == true)
		System.Runtime.InteropServices.Marshal.ReleaseComObject(comObject);
}

Resume Task Sequence

public static void ShowTSProgressUI()
{
	Type environmentType = Type.GetTypeFromProgID("Microsoft.SMS.TSEnvironment");
	dynamic tsEnv = Activator.CreateInstance(environmentType);

	Type progressType = Type.GetTypeFromProgID("Microsoft.SMS.TSProgressUI");
	dynamic tsProgress = Activator.CreateInstance(progressType);

	string orgName = tsEnv.Value["_SMSTSOrgName"];
	string pkgName = tsEnv.Value["_SMSTSPackageName"];
	string customMessage = tsEnv.Value["_SMSTSCustomProgressDialogMessage"];
	string currentAction = tsEnv.Value["_SMSTSCurrentActionName"];
	string nextInstructor = tsEnv.Value["_SMSTSNextInstructionPointer"];
	string maxStep = tsEnv.Value["_SMSTSInstructionTableSize"];

	tsProgress.ShowTSProgress(orgName, pkgName, customMessage, currentAction, nextInstructor, maxStep);

	if (System.Runtime.InteropServices.Marshal.IsComObject(tsEnv) == true)
		System.Runtime.InteropServices.Marshal.ReleaseComObject(tsEnv);

	if (System.Runtime.InteropServices.Marshal.IsComObject(tsProgress) == true)
		System.Runtime.InteropServices.Marshal.ReleaseComObject(tsProgress);
}

(710)

Nickolaj Andersen

Principal Consultant and Enterprise Mobility MVP since 2016. Nickolaj has been in the IT industry for the past 10 years specializing in Enterprise Mobility and Security, Windows devices and deployments including automation. Currently working for TrueSec as a Principal Consultant. Awarded as PowerShell Hero in 2015 by the community for his script and tools contributions. Creator of ConfigMgr Prerequisites Tool, ConfigMgr OSD FrontEnd, ConfigMgr WebService to name a few. Frequent speaker at conferences and user groups.

comments
  • Scott Milne
    Posted at 23:39 January 6, 2017
    Scott Milne
    Reply
    Author

    Excellent! Just what I was looking for…It doesn’t seem to pause the TS, however. Only closes the UI.

  • Leave a Reply