You can configure an existing mandatory advertisement for Wake On LAN by using the SMS_Advertisement class and properties.

To configure a mandatory advertisement for Wake On LAN

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

  2. Get the specific advertisement using the provided advertisement ID.

  3. Replace the AdvertFlags property value with the value indicating Wake On LAN.

  4. Save the advertisement with the new property

Example

The following example method configures a software distribution mandatory advertisement for Wake On LAN.

For information about calling the sample code, see Calling Configuration Manager Code Snippets.

Visual Basic Script  Copy Code
Sub SetWOLOnAdvertisment(connection, 		_
						 existingAdvertisementID)

	' Define a constant with the hexadecimal value for WAKE_ON_LAN_ENABLED. 
	WAKE_ON_LAN_ENABLED = &H00400000

	' 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 WAKE_ON_LAN_ENABLED

	' 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 SetWOLOnAdvertisment(WqlConnectionManager connection,
								 string existingAdvertisementID)
{
	// Define a constant with the hexadecimal value for WAKE_ON_LAN_ENABLED. 
	const Int32 WAKE_ON_LAN_ENABLED = 0x00400000;

	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 WAKE_ON_LAN_ENABLED value.
		advertisementToModify["AdvertFlags"].IntegerValue = advertisementToModify["AdvertFlags"].IntegerValue | WAKE_ON_LAN_ENABLED;

		// 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

swebemServices

  • Managed: WqlConnectionManager

  • VBScript: SWbemServices

A valid connection to the SMS Provider.

existingAdvertisementID

  • Managed: String

  • VBScript: String

The ID of the advertisment.

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.