Compartilhar via


How to Create a Program

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

The following example shows how to create a program, in Microsoft System Center Configuration Manager 2007, by using the SMS_Program Server WMI Class class and class properties.

Important

Any advertised program will fail to run when the maintenance windows that are defined on the client computer are set for a period that is less than that program's Maximum allowed run time setting. For more information, see Program Run Scenario Using Maintenance Windows in the Configuration Manager 2007 documentation.

To create a program

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Create the new program object by using the SMS_Program Server WMI Class class.

  3. Populate the new program properties.

    Tip

    When you create a program for a Task Sequence or a Virtual Application Package, the SMS_Program properties must be set to specific values. The following tables outline what those settings should be configured to.

    • Task Sequence

      Property Name Property Value

      ProgramName

      *

    • Virtual Application Package

      Property Name Property Value

      CommandLine

      PkgGUID={E742FFD6-D539-42CC-9827-73535FC81E06}:VersionGUID={19366289-8C55-44E2-A5EC-7B385EFB4C30}

      Note

      The GUID values are taken from the virtual application’s XML manifest file

      ProgramName

      [Virtual application]

  4. Save the new program and properties.

Example

The following example method creates a new program and populates its properties for use in software distribution.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Sub CreateProgram(connection, existingPackageID, newProgramName, newProgramComment, newProgramCommandLine, newMaxRunTime)
    
    ' Create the new program object.
    Set newProgram = connection.Get("SMS_Program").SpawnInstance_
    
    ' Populate the program properties.
    newProgram.PackageID = existingPackageID
    newProgram.ProgramName = newProgramName
    newProgram.Comment = newProgramComment
    newProgram.CommandLine = newProgramCommandLine
    newProgram.Duration = newMaxRunTime
    
    ' Save the new program and properties.
    newProgram.Put_
    
    ' Output new program name.
    wscript.echo "Created program: " & newProgramName

End Sub
public void CreateProgram(WqlConnectionManager connection, 
                          string existingPackageID, 
                          string newProgramName, 
                          string newProgramComment, 
                          string newProgramCommandLine,
                          int newMaxRunTime)
{
    try
    {
        // Create an instance of SMS_Program.
        IResultObject newProgram = connection.CreateInstance("SMS_Program");

        // Populate basic program values.
        newProgram["PackageID"].StringValue = existingPackageID;
        newProgram["ProgramName"].StringValue = newProgramName;
        newProgram["Comment"].StringValue = newProgramComment;
        newProgram["CommandLine"].StringValue = newProgramCommandLine;
        newProgram["Duration"].IntegerValue = newMaxRunTime;

        // Save the new program instance and values.
        newProgram.Put();

        Console.WriteLine("Created program: " + newProgramName);
    }
    catch (SmsException ex)
    {
        Console.WriteLine("Failed to create program. Error: " + ex.Message);
        throw;
    }
}

The example method has the following parameters:

Parameter Type Description

connection

swebemServices

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

existingPackageID

  • Managed: String

  • VBScript: String

The name of the package associated with the program.

newProgramName

  • Managed: String

  • VBScript: String

The name for the new program.

newProgramComment

  • Managed: String

  • VBScript: String

Comment that describes the program in the Configuration Manager console.

newProgramCommandLine

  • Managed: String

  • VBScript: String

The command line that runs when the program is launched.

newMaxRunTime

  • Managed: Integer

  • VBScript: Integer

The approximate duration, in minutes, of program execution on the client computer.

Compiling the Code

The C# example requires:

Namespaces

System

System.Collections.Generic

System.ComponentModel

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Robust Programming

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

Security

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

See Also

Concepts

Configuration Manager Software Distribution
Software Distribution Packages
Software Distribution Programs
How to Use Configuration Manager Objects with WMI
How to Use Configuration Manager Objects with Managed Code
How to Connect to an SMS Provider in Configuration Manager by Using Managed Code
How to Connect to an SMS Provider in Configuration Manager by Using WMI
SMS_Package Server WMI Class
SMS_Program Server WMI Class