下列範例示範如何使用 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;
}
}
範例方法具有下列參數:
參數 | Type | 描述 |
---|---|---|
connection swbemServices |
-管理: WqlConnectionManager - VBScript: SWbemServices |
SMS 提供者的有效連線。 |
existingAdvertisementID |
-管理: String - VBScript: String |
要修改之公告的識別碼。 |
正在編譯程式碼
C# 範例需要:
命名空間
系統
Microsoft。ConfigurationManagement.ManagementProvider
Microsoft。ConfigurationManagement.ManagementProvider.WqlQueryEngine
組件
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
mscorlib
健全的程式設計
如需錯誤處理的詳細資訊,請參閱關於Configuration Manager錯誤。