Udostępnij za pośrednictwem


How to Create a Package

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 package in Microsoft System Center Configuration Manager 2007 by using the SMS_Package Server WMI Class class and class properties.

To create a package

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

  2. Create the new package object by using the SMS_Package Server WMI Class class.

  3. Populate the new package properties.

    Tip

    When you are creating a Virtual Application Package, you must set the SMS_Package properties to specific values. Instances of the SMS_VirtualApp class must reference instances of the SMS_Package class that use the properties described in the following table.

    • Virtual Application Package

      Property Name Property Value

      PackageType

      7

      PkgSourceFlag

      2

      PkgSourcePath

      \\someserver\somesharepath

  4. Save the package.

Example

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

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

Sub CreatePackage(connection, newPackageName, newPackageDescription, newPackageSourceFlag, newPackageSourcePath)

    ' Create the new package object. 
    Set newPackage = connection.Get("SMS_Package").SpawnInstance_

    ' Populate the new package properties.
    newPackage.Name = newPackageName
    newPackage.Description = newPackageDescription
    newPackage.PkgSourceFlag = newPackageSourceFlag
    newPackage.PkgSourcePath = newPackageSourcePath

    ' Save the package.
    newPackage.Put_

    ' Output the new package name.
    wscript.echo "Created package: "  & newPackageDescription

End Sub
public void CreatePackage(WqlConnectionManager connection, string newPackageName, string newPackageDescription, int newPackageSourceFlag, string newPackageSourcePath)
{
    try
    {
        // Create new package object.
        IResultObject newPackage = connection.CreateInstance("SMS_Package");

        // Populate new package properties.
        newPackage["Name"].StringValue = newPackageName;
        newPackage["Description"].StringValue = newPackageDescription;
        newPackage["PkgSourceFlag"].IntegerValue = newPackageSourceFlag;
        newPackage["PkgSourcePath"].StringValue = newPackageSourcePath;

        // Save new package and new package properties.
        newPackage.Put();

        // Output new package name.
        Console.WriteLine("Created package" + newPackageName);
    }

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

The example method has the following parameters:

Parameter Type Description

connection

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

newPackageName

  • Managed: String

  • VBScript: String

The name of the new package.

newPackageDescription

  • Managed: String

  • VBScript: String

The description for the new package.

newPackageSourceFlag

  • Managed: Integer

  • VBScript: Integer

The package source.

newPackageSourcePath

  • Managed: String

  • VBScript: String

The path to the package source.

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
About the Configuration Manager Site Control File
How to Read and Write to the Configuration Manager Site Control File by Using Managed Code
How to Read and Write to the Configuration Manager Site Control File by Using WMI
SMS_SCI_Component Server WMI Class
SMS_Package Server WMI Class