How to Create 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 create a software metering rule, in Microsoft System Center Configuration Manager 2007, by creating an instance of the SMS_MeteredProductRule class and populating the properties.

To create software metering rule

  1. Set up a connection to the SMS Provider.

  2. Create the new software metering rule object by using the SMS_MeteredProductRule class.

  3. Populate the new software metering rule properties.

  4. Save the new software metering rule and properties.

Example

The following example method shows how to create a software metering rule by creating an instance of the SMS_MeteredProductRule class and populating the properties.

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

Sub CreateSWMRule(connection,              _
                  newProductName,          _
                  newFileName,             _
                  newOriginalFileName,     _
                  newFileVersion,          _
                  newLanguageID,           _
                  newSiteCode,             _
                  newApplyToChildSites)               

    ' Create the new MeteredProductRule object. 
    Set newSWMRule = connection.Get("SMS_MeteredProductRule").SpawnInstance_
    
    ' Populate the SMS_MeteredProductRule properties.
    newSWMRule.ProductName= newProductName
    newSWMRule.FileName = newFileName
    newSWMRule.OriginalFileName =  newOriginalFileName
    newSWMRule.FileVersion = newFileVersion
    newSWMRule.LanguageID = newLanguageID
    newSWMRule.SiteCode = newSiteCode
    newSWMRule.ApplyToChildSites = newApplyToChildSites
            
    ' Save the new rule and properties.
    newSWMRule.Put_ 
    
    ' Output new rule name.
    Wscript.Echo "Created new SWM Rule: " & newProductName                  
                                    
End Sub
public void CreateSWMRule(WqlConnectionManager connection,
                          string newProductName,
                          string newFileName,
                          string newOriginalFileName,
                          string newFileVersion,
                          string newLanguageID,
                          string newSiteCode,
                          string newApplyToChildSites)
{
    try
    {
        // Create the new SMS_AuthorizationList object.
        IResultObject newSWMRule = connection.CreateInstance("SMS_MeteredProductRule");

        // Populate the new SMS_MeteredProductRule object properties.
        newSWMRule["ProductName"].StringValue = newProductName;
        newSWMRule["FileName"].StringValue = newFileName;
        newSWMRule["OriginalFileName"].StringValue = newOriginalFileName;
        newSWMRule["FileVersion"].StringValue = newFileVersion;
        newSWMRule["LanguageID"].StringValue = newLanguageID;
        newSWMRule["SiteCode"].StringValue = newSiteCode;
        newSWMRule["ApplyToChildSites"].StringValue = newApplyToChildSites;
                        
        // Save changes.
        newSWMRule.Put();

        Console.WriteLine();
        Console.WriteLine("Created new SWM Rule: " + newProductName);
    }

    catch (SmsException ex)
    {
        Console.WriteLine("Failed to create SWM 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.

newProductName

  • Managed: String

  • VBScript: String

The new product name.

newFileName

  • Managed: String

  • VBScript: String

The new file name.

newOriginalFileName

  • Managed: String

  • VBScript: String

The new original file name.

newFileVersion

  • Managed: String

  • VBScript: String

The new file version.

newLanguageID

  • Managed: String

  • VBScript: String

The new language ID.

newSiteCode

  • Managed: String

  • VBScript: String

The new site code.

newApplyToChildSites

  • Managed: String

  • VBScript: String

Determines whether the rule will apply to child sites.

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