How to Configure an Advertisement to Allow Reboots Outside of a Maintenance Window
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
The following example shows how to configure an advertisement to allow reboots outside of a maintenance window by using the SMS_Advertisement Server WMI Class class and the AdvertFlags class property in Microsoft System Center Configuration Manager 2007.
To configure an advertisement to allow reboots outside of a maintenance window
Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.
Load an existing advertisement object using the SMS_Advertisement Server WMI Class class.
Modify the AdvertFlags property using the hexadecimal value for REBOOT_OUTSIDE_OF_MAINTENANCE_WINDOW.
Save the modified advertisement and properties.
Example
The following example method configures an existing advertisement to allow reboots outside of a maintenance window.
Important
The hexadecimal values that define the AdvertFlags property are listed in the SMS_Advertisement Server WMI Class class reference material.
For information about calling the sample code, see Calling Configuration Manager Code Snippets.
Sub ModifyAdvertisementToRebootOutsideOfMaintenanceWindows(connection, _
existingAdvertisementID)
' Define a constant with the hex value for the REBOOT_OUTSIDE_OF_MAINTENANCE_WINDOWS.
REBOOT_OUTSIDE_OF_MAINTENANCE_WINDOWS = &H00200000
' Get the specific advertisement instance to modify.
Set advertisementToModify = connection.Get("SMS_Advertisement.AdvertisementID='" & existingAdvertisementID & "'")
' List the existing property values.
Wscript.Echo " "
Wscript.Echo "Values before change: "
Wscript.Echo "--------------------- "
Wscript.Echo "Advertisement Name: " & advertisementToModify.AdvertisementName
Wscript.Echo "Advertisement Flags (integer): " & advertisementToModify.AdvertFlags
' Set the new property value.
advertisementToModify.AdvertFlags = advertisementToModify.AdvertFlags OR REBOOT_OUTSIDE_OF_MAINTENANCE_WINDOWS
' Save the advertisement.
advertisementToModify.Put_
' Output the new property values.
Wscript.Echo " "
Wscript.Echo "Values after change: "
Wscript.Echo "--------------------- "
Wscript.Echo "Advertisement Name: " & advertisementToModify.AdvertisementName
Wscript.Echo "Advertisement Flags (integer): " & advertisementToModify.AdvertFlags
End Sub
public void ModifySWDAdvertisementToRebootOutsideOfMaintenanceWindows(WqlConnectionManager connection,
string existingAdvertisementID)
{
// Define a constant with the hex value for REBOOT_OUTSIDE_OF_MAINTENANCE_WINDOWS.
const Int32 REBOOT_OUTSIDE_OF_MAINTENANCE_WINDOWS = 0x00200000;
try
{
// Get the specific advertisement instance to modify.
IResultObject advertisementToModify = connection.GetInstance(@"SMS_Advertisement.AdvertisementID='" + existingAdvertisementID + "'");
// List the existing property values.
Console.WriteLine();
Console.WriteLine("Values before change:");
Console.WriteLine("_____________________");
Console.WriteLine("Advertisement Name: " + advertisementToModify["AdvertisementName"].StringValue);
Console.WriteLine("Advertisement Flags (integer): " + advertisementToModify["AdvertFlags"].IntegerValue);
// Modify the AdvertFlags value to include the REBOOT_OUTSIDE_OF_MAINTENANCE_WINDOWS value.
advertisementToModify["AdvertFlags"].IntegerValue = advertisementToModify["AdvertFlags"].IntegerValue | REBOOT_OUTSIDE_OF_MAINTENANCE_WINDOWS;
// Save the advertisement with the new value.
advertisementToModify.Put();
// Reload the advertisement to verify the change.
advertisementToModify.Get();
// List the existing (modified) property values.
Console.WriteLine();
Console.WriteLine("Values after change:");
Console.WriteLine("_____________________");
Console.WriteLine("Advertisement Name: " + advertisementToModify["AdvertisementName"].StringValue);
Console.WriteLine("Advertisement Flags (integer): " + advertisementToModify["AdvertFlags"].IntegerValue);
}
catch (SmsException ex)
{
Console.WriteLine("Failed to modify advertisement. Error: " + ex.Message);
throw;
}
}
The example method has the following parameters:
Parameter | Type | Description |
---|---|---|
connection swbemServices |
|
A valid connection to the SMS Provider. |
existingAdvertisementID |
|
The ID of the advertisement to modify. |
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
Concepts
Configuration Manager Software Distribution
Software Distribution Advertisements
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_Advertisement Server WMI Class