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.
You create a software metering rule, in Configuration Manager, by creating an instance of the SMS_MeteredProductRule
class and populating the properties.
To create software metering rule
Set up a connection to the SMS Provider.
Create the new software metering rule object by using the
SMS_MeteredProductRule
class.Populate the new software metering rule properties.
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,
int newLanguageID,
string newSiteCode,
bool 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"].IntegerValue = newLanguageID;
newSWMRule["SiteCode"].StringValue = newSiteCode;
newSWMRule["ApplyToChildSites"].BooleanValue = 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: Integer - VBScript: Integer |
The new language ID. |
newSiteCode |
- Managed: String - VBScript: String |
The new site code. |
newApplyToChildSites |
- Managed: Boolean - VBScript: Boolean |
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.
.NET Framework Security
For more information about securing Configuration Manager applications, see Configuration Manager role-based administration.
See Also
Configuration Manager Software Development Kit
SMS_MeteredProductRule Server WMI Class