How to Enable or Disable 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 enable or disable 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 then setting the Enabled value.
To enable or disable a software metering rule
Set up a connection to the SMS Provider.
Load the software metering rule object by using the SMS_MeteredProductRule class and a known software metering rule ID.
Set the Enabled property to true or false.
Example
The following example method shows how to enable or disable a software metering rule by loading the instance of the software metering rule that is identified by the software metering rule ID and setting the Enabled property.
Important
The rule ID corresponds to the value that is stored in the property RuleID. The Configuration Manager console displays a Rule ID column, which actually corresponds to the value that is stored in the property SecurityID.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
' Enable or disable a software metering rule.
Sub EnableDisableSoftwareMeteringRule(connection, _
existingSWMRuleID, _
enableDisableSWMRule)
' Get an existing software metering rule to enable or disable.
Set existingSWMRule = connection.Get("SMS_MeteredProductRule.RuleID='" & existingSWMRuleID & "'")
' Get file name for output.
fileName = existingSWMRule.FileName
' Enable or disable the rule.
existingSWMRule.Enabled = enableDisableSWMRule
' Save the new rule and properties.
existingSWMRule.Put_
' Output a success message.
Wscript.Echo "SWM rule ID: " & existingSWMRuleID
Wscript.Echo "Rule name: " & fileName
Wscript.Echo "Set enabled to: " & enableDisableSWMRule
End Sub
public void EnableDisableSoftwareMeteringRule(WqlConnectionManager connection,
string existingSWMRuleID,
bool enableDisableSWMRule)
{
try
{
// Get the specific software metering rule to enable or disable.
IResultObject existingSWMRule = connection.GetInstance(@"SMS_MeteredProductRule.RuleID='" + existingSWMRuleID + "'");
// Get rule name for output message.
string productName = existingSWMRule["ProductName"].StringValue;
// Set the software metering rule.
existingSWMRule["Enabled"].BooleanValue = enableDisableSWMRule;
// Save changes.
existingSWMRule.Put();
// Output a success message.
Console.WriteLine("SWM rule ID: " + existingSWMRuleID);
Console.WriteLine("Rule name: " + productName);
Console.WriteLine("Set enabled to: " + enableDisableSWMRule);
}
catch (SmsException ex)
{
Console.WriteLine("Failed to modify software metering rule. Error: " + ex.Message);
throw;
}
}
The example method has the following parameters:
Parameter |
Type |
Description |
Connection |
|
A valid connection to the SMS Provider. |
existingSWMRuleID |
|
Identifies a specific software metering rule. In this case, identifies the specific software metering rule that will be enabled or disabled. |
enableDisableSWMRule |
|
Enables or disables the software metering rule. true - Enabled false - Disabled |
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