The following example shows how to set the distribute on demand flag property of an existing package by using the SMS_Package Server WMI Class class in System Center 2012 Configuration Manager.
To set the distribute on demand flag
-
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
-
Load the existing package object by using SMS_Package Server WMI Class class.
-
Populate the package flag property.
-
Save the package and the new package properties.
Example
The following example method sets the distribute on demand flag for a package.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Visual Basic Script | ![]() |
---|---|
Sub SetDistributeOnDemandFlag(connection, _ existingPackageID) ' Define a constant with the hexadecimal value for the DISTRIBUTE_ON_DEMAND. DISTRIBUTE_ON_DEMAND = &H40000000 ' Get the specific package instance to modify. Set packageToModify = connection.Get("SMS_Package.PackageID='" & existingpackageID & "'") ' List the existing property values. Wscript.Echo " " Wscript.Echo "Values before change: " Wscript.Echo "--------------------- " Wscript.Echo "Package Name: " & packageToModify.Name Wscript.Echo "Package Flags (integer): " & packageToModify.PkgFlags ' Set the new property value. packageToModify.PkgFlags = packageToModify.PkgFlags OR DISTRIBUTE_ON_DEMAND ' Save the package. packageToModify.Put_ ' Output the new property values. Wscript.Echo " " Wscript.Echo "Values after change: " Wscript.Echo "--------------------- " Wscript.Echo "Package Name: " & packageToModify.Name Wscript.Echo "Package Flags (integer): " & packageToModify.PkgFlags End Sub |
C# | ![]() |
---|---|
public void SetDistributeOnDemandFlag(WqlConnectionManager connection, string existingPackageID) { // Define a constant with the hexadecimal value for DISTRIBUTE_ON_DEMAND. const Int32 DISTRIBUTE_ON_DEMAND = 0x40000000; try { // Get the specific package instance to modify. IResultObject packageToModify = connection.GetInstance(@"SMS_Package.PackageID='" + existingPackageID + "'"); // List the existing property values. Console.WriteLine(); Console.WriteLine("Values before change:"); Console.WriteLine("_____________________"); Console.WriteLine("Package Name: " + packageToModify["Name"].StringValue); Console.WriteLine("Package Flags (integer): " + packageToModify["PkgFlags"].IntegerValue); // Modify the PkgFlags value to include the DISTRIBUTE_ON_DEMAND value. packageToModify["PkgFlags"].IntegerValue = packageToModify["PkgFlags"].IntegerValue | DISTRIBUTE_ON_DEMAND; // Save the package with the new value. packageToModify.Put(); // Reload the package to verify the change. packageToModify.Get(); // List the existing (modified) property values. Console.WriteLine(); Console.WriteLine("Values after change:"); Console.WriteLine("_____________________"); Console.WriteLine("Package Name: " + packageToModify["Name"].StringValue); Console.WriteLine("Package Flags (integer): " + packageToModify["PkgFlags"].IntegerValue); } catch (SmsException ex) { Console.WriteLine("Failed to modify package. Error: " + ex.Message); throw; } } |
The example method has the following parameters:
Parameter | Type | Description |
---|---|---|
connection swebemServices |
|
A valid connection to the SMS Provider. |
existingPackageID |
|
The ID of the package. |
Compiling the Code
The C# example requires:
Namespaces
System
System.Collections.Generic
System.ComponentModel
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
Tasks
How to Connect to an SMS Provider in Configuration Manager by Using Managed CodeHow to Connect to an SMS Provider in Configuration Manager by Using WMI
Reference
SMS_Package Server WMI ClassConcepts
Distribution PointsSoftware Distribution Packages
How to Use Configuration Manager Objects with WMI
How to Use Configuration Manager Objects with Managed Code