次の方法で共有


ハートビート検出を構成する方法

Configuration Managerで、必要なサイト コントロール ファイルの設定を変更して、ハートビート検出の設定を構成します。

ハートビート検出を構成するには

  1. SMS プロバイダーへの接続を設定します。

  2. SMS_SCI_Component クラスを使用して、サイト コントロール ファイルの [ハートビート検出] セクションに接続します。

  3. 使用可能なプロパティの配列をLoopし、必要に応じて変更を加えます。

  4. サイト コントロール ファイルに変更をコミットします。

次の例では、 SMS_SCI_Component クラスを使用してサイト コントロール ファイルに接続し、プロパティを変更することで、ハートビート検出の設定を設定します。

サンプル コードの呼び出しについては、「Configuration Manager コード スニペットの呼び出し」を参照してください。


Sub ConfigureHeartbeatDiscoverySettings1(swbemServices,                       _
                                         swbemContext,                        _
                                         siteCode,                            _
                                         serverName,                          _
                                         newHeartbeatSiteControlFileSchedule)

    ' Load site control file and get the SMS_SITE_CONTROL_MANAGER section.
    swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext

    Query = "SELECT * FROM SMS_SCI_Component " &                         _
    "WHERE ItemName = 'SMS_SITE_CONTROL_MANAGER|" & serverName & "' " &  _
    "AND SiteCode = '" & siteCode & "'"

    ' Get the SMS Software Update Point properties.
    Set SCIComponentSet = swbemServices.ExecQuery(Query, ,wbemFlagForwardOnly Or wbemFlagReturnImmediately, swbemContext)

    ' Only one instance is returned from the query.
    For Each SCIComponent In SCIComponentSet

        ' Display the server name.
        wscript.echo "Server: " & SCIComponent.Name

        ' Loop through the array of embedded SMS_EmbeddedProperty instances.
        For Each vProperty In SCIComponent.Props

            ' Setting: Heartbeat Site Control File Schedule.
            If vProperty.PropertyName = "Heartbeat Site Control File Schedule" Then
                wscript.echo " "
                wscript.echo vProperty.PropertyName
                wscript.echo "Current value " &  vProperty.Value1

                'Modify the value.
                vProperty.Value1 = newHeartbeatSiteControlFileSchedule
                wscript.echo "New value " & newHeartbeatSiteControlFileSchedule
            End If

         Next

         ' Update the component in your copy of the site control file. Get the path
         ' to the updated object, which could be used later to retrieve the instance.
          Set SCICompPath = SCIComponent.Put_(wbemChangeFlagUpdateOnly, swbemContext)

    Next

    ' Commit the change to the actual site control file.
    Set InParams = swbemServices.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_
    InParams.SiteCode = siteCode
    swbemServices.ExecMethod "SMS_SiteControlFile", "CommitSCF", InParams, , swbemContext

End Sub

' SEPARATE EXAMPLE TO ENABLE HEARTBEAT DISCOVERY ON THE CLIENT
Sub ConfigureHeartbeatDiscoverySettings2(swbemServices,                       _
                                         swbemContext,                        _
                                         siteCode,                            _
                                         enableDisableHeartbeatDDR)

    ' Load site control file and get the SMS_SCI_ClientConfig section.
    swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext

    Query = "SELECT * FROM SMS_SCI_ClientConfig " &   _
    "WHERE ItemName  = 'Client Properties'" & _
    "AND SiteCode = '" & siteCode & "'"

     Set SCIComponentSet = swbemServices.ExecQuery(Query, ,wbemFlagForwardOnly Or wbemFlagReturnImmediately, swbemContext)

    ' Only one instance is returned from the query.
    For Each SCIComponent In SCIComponentSet

        'Loop through the array of embedded SMS_EmbeddedProperty instances.
        For Each vProperty In SCIComponent.Props

            ' Setting: Enable Heartbeat DDR
            If vProperty.PropertyName = "Enable Heartbeat DDR" Then
                wscript.echo " "
                wscript.echo vProperty.PropertyName
                wscript.echo "Current value " &  vProperty.Value

                'Modify the value.
                vProperty.Value = enableDisableHeartbeatDDR
                wscript.echo "New value " & enableDisableHeartbeatDDR
            End If

        Next

        ' Update the component in your copy of the site control file. Get the path
        ' to the updated object, which could be used later to retrieve the instance.
        Set SCICompPath = SCIComponent.Put_(wbemChangeFlagUpdateOnly, swbemContext)

    Next

    ' Commit the change to the actual site control file.
    Set InParams = swbemServices.Get("SMS_SiteControlFile").Methods_("CommitSCF").InParameters.SpawnInstance_
    InParams.SiteCode = siteCode
    swbemServices.ExecMethod "SMS_SiteControlFile", "CommitSCF", InParams, , swbemContext

End Sub


public void ConfigureHeartbeatDiscoverySettings(WqlConnectionManager connection,
                                                string siteCode,
                                                string serverName,
                                                string newHeartbeatSiteControlFileSchedule,
                                                string newEnableDisableHeartbeatDDR)
{

    try
    {
    // Change the Heartbeat Site Control File Schedule value.

        // Connect to SMS_SITE_CONTROL_MANAGER section of the site control file.
         IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_Component.FileType=2,ItemType='Component',SiteCode='" + siteCode + "',ItemName='SMS_SITE_CONTROL_MANAGER|" + serverName + "'");

        // Temporary copy of the embedded properties.
        Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties;

        foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)
        {
            // Property: Heartbeat Site Control File Schedule
            if (kvp.Value.PropertyList["PropertyName"] == "Heartbeat Site Control File Schedule")
            {
                Console.WriteLine();
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
                Console.WriteLine("Current value: " + embeddedProperties["Heartbeat Site Control File Schedule"]["Value1"].StringValue);

                embeddedProperties["Heartbeat Site Control File Schedule"]["Value1"].StringValue = newHeartbeatSiteControlFileSchedule;
                Console.WriteLine("New value    : " + newHeartbeatSiteControlFileSchedule);
            }
        }

        // Store the settings that have changed.
        siteDefinition.EmbeddedProperties = embeddedProperties;

        // Save the settings.
        siteDefinition.Put();

    }
    catch (SmsException ex)
    {
        Console.WriteLine();
        Console.WriteLine("Failed. Error: " + ex.InnerException.Message);
    }

    try
    {
    // Change the Enable Heartbeat DDR value.

        // Connect to SMS_SCI_ClientConfig section of the site control file.
    IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_ClientConfig.FileType=2,ItemType='Client Configuration',SiteCode='" + siteCode + "',ItemName='Client Properties'");

        // Create temporary working copy of embedded properties.
        Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties;

        foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)
        {
            // Setting: Enable Heartbeat DDR
            if (kvp.Value.PropertyList["PropertyName"] == "Enable Heartbeat DDR")
            {
                Console.WriteLine();
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
                Console.WriteLine("Current value: " + kvp.Value.PropertyList["Value"]);

                // Change value using the newEnableDisableHeartbeatDDR value passed in.
                embeddedProperties["Enable Heartbeat DDR"]["Value"].StringValue = newEnableDisableHeartbeatDDR;
                Console.WriteLine("New value    : " + newEnableDisableHeartbeatDDR);
            }
        }

        // Store the settings that have changed.
        siteDefinition.EmbeddedProperties = embeddedProperties;

        // Save the settings.
        siteDefinition.Put();
    }

    catch (SmsException ex)
    {
        Console.WriteLine("Failed. Error: " + ex.InnerException.Message);
        throw;
    }

}

このメソッドの例には、次のパラメーターがあります。

パラメーター 説明
- connection
- swbemServices
-管理: WqlConnectionManager
- VBScript: SWbemServices
SMS プロバイダーへの有効な接続。
swbemContext - VBScript: SWbemContext 有効なコンテキスト オブジェクト。 詳細については、「WMI を使用してConfiguration Managerコンテキスト修飾子を追加する方法」を参照してください。
siteCode -管理: String
- VBScript: String
サイト コード。
serverName -管理: String
- VBScript: String
サーバー名。
newHeartbeatSiteControlFileSchedule -管理: String
- VBScript: String
クライアントがハートビート データ検出レコード (DDR) を生成する頻度を定義するスケジュール。
- newEnableDisableHeartbeatDDR
- enableDisableHeartbeatDDR
-管理: String
- VBScript: String
ハートビート DDR を有効または無効にする値。

無効 - 0

有効 - 1

コードのコンパイル

この C# の例では、次のものが必要です。

名前空間

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

堅牢なプログラミング

エラー処理の詳細については、「Configuration Manager エラーについて」を参照してください。

.NET Framework のセキュリティ

Configuration Manager アプリケーションのセキュリティ保護の詳細については、「ロールベースの管理Configuration Manager」を参照してください。

関連項目

Configuration Managerサイト コントロール ファイルについてマネージド コードを使用してConfiguration Manager サイト コントロール ファイルの読み取りと書き込みを行う方法 WMI SMS_SCI_Component サーバー WMI クラスを使用してConfiguration Managerサイト コントロール ファイルに読み書きする方法スケジュールについてスケジュール トークンを作成する方法