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

  1. Set up a connection to the SMS Provider. For more information, see About the SMS Provider in Configuration Manager.

  2. Load an existing advertisement object using the SMS_Advertisement Server WMI Class class.

  3. Modify the AdvertFlags property using the hexadecimal value for REBOOT_OUTSIDE_OF_MAINTENANCE_WINDOW.

  4. 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.

Visual Basic Script  Copy Code
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
C#  Copy Code
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

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

existingAdvertisementID

  • Managed: String

  • VBScript: String

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


Send comments about this topic to Microsoft.