以下示例演示如何使用 SMS_Advertisement
Configuration Manager 中的 类和 AdvertFlags
类属性将播发配置为允许在维护时段外重新启动。
配置播发以允许在维护时段外重新启动
设置与 SMS 提供程序的连接。
使用
SMS_Advertisement
类加载现有播发对象。AdvertFlags
使用 的十六进制值REBOOT_OUTSIDE_OF_MAINTENANCE_WINDOW
修改 属性。保存修改后的播发和属性。
示例
以下示例方法将现有播发配置为允许在维护时段外重新启动。
重要
引用材料中列出了定义 属性的AdvertFlags
SMS_Advertisement
十六进制值。
有关调用示例代码的信息,请参阅调用Configuration Manager代码片段。
Sub ModifyAdvertisementToRebootOutsideOfMaintenanceWindows(connection, existingAdvertisementID)
' Define a constant with the hexadecimal value for the REBOOT_OUTSIDE_OF_MAINTENANCE_WINDOWS.
Const REBOOT_OUTSIDE_OF_MAINTENANCE_WINDOWS = &H00200000
Dim advertisementToModify
' 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 hexadecimal 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;
}
}
示例方法具有以下参数:
参数 | 类型 | 说明 |
---|---|---|
connection swbemServices |
-管理: WqlConnectionManager - VBScript: SWbemServices |
与 SMS 提供程序的有效连接。 |
existingAdvertisementID |
-管理: String - VBScript: String |
要修改的播发的 ID。 |
编译代码
C# 示例需要:
命名空间
系统警报
Microsoft。ConfigurationManagement.ManagementProvider
Microsoft。ConfigurationManagement.ManagementProvider.WqlQueryEngine
Assembly
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
mscorlib
可靠编程
有关错误处理的详细信息,请参阅关于Configuration Manager错误。