How to Set the Distribute on Demand Flag
Updated: November 1, 2013
Applies To: System Center 2012 Configuration Manager, System Center 2012 Configuration Manager SP1, System Center 2012 R2 Configuration Manager
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 R2 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.
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
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; } }
Compiling the Code
The C# example requires:
System
System.Collections.Generic
System.ComponentModel
Microsoft.ConfigurationManagement.ManagementProvider
Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine
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 Securing Configuration Manager Applications.
Configuration Manager Software Distribution
Distribution Points
Software Distribution Packages
How to Use Configuration Manager Objects with WMI
How to Use Configuration Manager Objects with Managed Code
How to Connect to an SMS Provider in Configuration Manager by Using Managed Code
How to Connect to an SMS Provider in Configuration Manager by Using WMI
SMS_Package Server WMI Class
The example method has the following parameters:
Parameter
Type
Description
connection
swebemServices
Managed: WqlConnectionManager
VBScript: SWbemServices
A valid connection to the SMS Provider.
existingPackageID
Managed: String
VBScript: String
The ID of the package.