Partager via


How to Run a Program on a Configuration Manager Client

Applies To: System Center Configuration Manager 2007, System Center Configuration Manager 2007 R2, System Center Configuration Manager 2007 R3, System Center Configuration Manager 2007 SP1, System Center Configuration Manager 2007 SP2

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

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

Concepts

How to Configure the Software Distribution Advertised Programs Client Agent Cache
How to Run a Program on a Configuration Manager Client
Configuration Manager Client Automation
Software Distribution Client Control Panel Automation
UIResourceMgr Class
Program Class
Programs Class
SMS_Program Server WMI Class
SMS_Package Server WMI Class
How to Call Configuration Manager COM Automation Objects