Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The following example shows how to delete a package in Configuration Manager by using the SMS_Package class.
Note
Any reference to this package, such as an advertisement or task sequence, should be cleaned up before deleting the package
To delete a package
Set up a connection to the SMS Provider.
Load the existing package object by using the
SMS_Packageclass.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). Dim packageToDelete
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 |
|---|---|---|
connectionswbemServices |
- 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
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
mscorlib
Robust Programming
For more information about error handling, see About Configuration Manager Errors.
.NET Framework Security
See Also
Software distribution overview SMS_SCI_Component Server WMI Class