In Microsoft System Center Configuration Manager 2007, you run an available program on a Configuration Manager 2007 client by using the resource manager (UIResourceMgrClass) object ExecuteProgram method. ExecuteProgram uses the program identifier and package identifier to identify the program to be run.

Note
You can obtain program and package identifiers by enumerating the available programs on a client. For more information, see How to View Available Programs on a Configuration Manager Client.

Procedures

To run a program on a Configuration Manager client
  1. Get the Configuration Manager client resource manager object (UIResourceMgrClass).

  2. From the UIResourceMgrClass object, call GetProgram, providing the program identifier and package identifier, to verify that the program exists.

  3. From the UIResourceMgrClass object, call ExecuteProgram , providing the program identifier and package identifier, to run the program.

Example

Description

The following example method runs a program identified by its program identifier and package identifier. The program is not run if there are any mandatory programs pending.

For information about calling the sample code, see How to Call Configuration Manager COM Automation Objects.

Code

Visual Basic Script  Copy Code
Sub RunProgram(programId, packageId)

	On Error Resume Next

	Dim oUIResource 
	Dim oPrograms 
	Dim oProgram 

	Set oUIResource = CreateObject ("UIResource.UIResourceMgr")

	If oUIResource Is Nothing Then 
		wscript.echo "Could not create Resource Object - quitting"
		Exit Sub
	End If

	if oUIResourceMgr.IsMandatoryProgramPending = 1 Then
		Wscript.Echo "Mandatory program pending. Try again later."
		Set oUIResource=Nothing
		Exit Sub
	End If

	Set oProgram = oUIResource.GetProgram(programId,packageId)
	if oProgram is Nothing Then
		WScript.Echo "Couldn't get the program"
		Set oUIResource=Nothing
		Exit Sub
	End If

	Wscript.Echo "Running program: " & oProgram.FullName
	oUIResource.ExecuteProgram programId, packageID 
 
	Set oProgram=Nothing
	Set oUIResource=Nothing

End Sub
C#  Copy Code
public void RunProgram(string programId, string packageId)
{
	ProgramCls prog;

	try
	{
		UIResourceMgrClass uiResMgr = new UIRESOURCELib.UIResourceMgrClass();

		if (uiResMgr.IsMandatoryProgramPending()==1)
		{
			Console.WriteLine("Mandatory program pending. Try again later.");
			return;
	}

	 
		try
		{
			prog = uiResMgr.GetProgram(programId, packageId);
	}
		catch(COMException e)
		{
			Console.WriteLine("Couldn't get program: " + e.Message);
			throw;
	}

		Console.WriteLine("Running program: " + prog.FullName);
		uiResMgr.ExecuteProgram(programId, packageId, 0);
}
	catch (COMException e)
	{
		Console.WriteLine("Failed to run program " + e.Message);
		throw;
}
}

Comments

The example method has no parameters.

Compiling the Code

This C# example requires:

Namespaces

System

System.Collections.Generic

System.Text

System.Runtime.InteropServices

UIRESOURCELib

COM Reference

UIResource 1.0 Type Library.

Robust Programming

For more information about error handling, see About Configuration Manager Errors.

Security

For more information about securing Configuration Manager applications, see About Securing Configuration Manager Applications.

See Also


Send comments about this topic to Microsoft.