Compartir a través de


How to Delete 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 delete a package in Microsoft System Center Configuration Manager 2007 by using the SMS_Package Server WMI Class class.

To delete a package

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

  2. Load the existing package object by using the SMS_Package Server WMI Class class.

  3. Delete the package by using the delete method.

Example

The following example method deletes an existing package.

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

Sub DeleteAPackage(connection, existingPackageID)

    ' Get the specified package instance (passed in as existingPackageID).
    Set packageToDelete = connection.Get("SMS_Package.PackageID='" & existingPackageID & "'")
    
    ' Delete the package.
    PackageToDelete.Delete_
    
    ' Output package ID of deleted package.
    wscript.echo "Deleted Package ID: " & existingPackageID

End Sub
public void DeleteAPackage(WqlConnectionManager connection, string existingPackageID)
{
    try
    {
        // Get the specified package instance (passed in as existingPackageID).
        IResultObject packageToDelete = connection.GetInstance(@"SMS_Package.PackageID='" + existingPackageID + "'");

        // Delete the package instance.
        packageToDelete.Delete();

        // Output package ID of deleted package.
        Console.WriteLine("Deleted Package ID: " + existingPackageID);
    }

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

The example method has the following parameters:

Parameter Type Description

connection

swbemServices

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

existingPackageID

  • Managed: String

  • VBScript: String

The ID of the existing package.

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