Compartilhar via


How to Delete a Software Metering Rule

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

You delete a software metering rule, in Microsoft System Center Configuration Manager 2007, by loading the instance of the software metering rule that is identified by the software metering rule ID and calling the delete method.

To delete a software metering rule

  1. Set up a connection to the SMS Provider.

  2. Load the software metering rule object by using the SMS_MeteredProductRule class and a known software metering rule ID.

  3. Delete the software metering rule by using the delete method.

Example

The following example method shows how to delete a software metering rule by loading an instance of the software metering rule that is identified by the software metering rule ID and calling the delete method.

Important

The rule ID corresponds to the value stored in the property RuleID. The Configuration Manager 2007 console displays a Rule ID column, which actually corresponds to the value stored in the property SecurityID.

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

' Delete a software metering rule.
 Sub DeleteSWMRule(connection,                  _
                   existingSWMRuleID)                         

    ' Get an existing software metering rule to delete. 
    Set existingSWMRule = connection.Get("SMS_MeteredProductRule.RuleID='" & existingSWMRuleID & "'")  
    
    ' Get file name for output.
    fileName = existingSWMRule.FileName
       
    ' Delete the software metering rule.
    existingSWMRule.Delete_
    
    ' Output a success message.
    Wscript.Echo "Deleted SWM rule: " & existingSWMRuleID
    Wscript.Echo "Rule name: " & fileName
                                   
 End Sub
public void DeleteSWMRule(WqlConnectionManager connection,
                          string existingSWMRuleID)
{
    try
    {
        // Get the specific SWM Rule to delete.

        IResultObject existingSWMRule = connection.GetInstance(@"SMS_MeteredProductRule.RuleID='" + existingSWMRuleID + "'");

        // Get file name for output message.
        string fileName = existingSWMRule["FileName"].StringValue;

        // Delete the software metering rule.
        existingSWMRule.Delete();

        // Output a success message.
        Console.WriteLine("Deleted SWM rule: " + existingSWMRuleID);
        Console.WriteLine("Rule name: " + fileName);
    }

    catch (SmsException ex)
    {
        Console.WriteLine("Failed to delete the software metering rule. 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.

existingSWMRuleID

  • Managed: String

  • VBScript: String

Identifies a specific software metering rule. In this case, identifies the specific software metering rule that will be deleted.

Compiling the Code

This C# example requires:

Namespaces

System

System.Collections.Generic

System.Text

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

System Center Configuration Manager Software Development Kit
Configuration Manager Software Metering
SMS_MeteredProductRule Server WMI Class