次の方法で共有


Configuration Managerで 2 台のコンピューター間の関連付けを作成する方法

Configuration Managerでは、クラス SMS_StateMigrationで AddAssociation メソッドを呼び出して、参照コンピューターとコピー先コンピューターの間に関連付けを作成します。

注:

関連付けを削除するには、 クラス SMS_StateMigration で DeleteAssociation メソッド を呼び出します。

2 台のコンピューター間に関連付けを作成するには

  1. SMS プロバイダーへの接続を設定します。 詳細については、「 SMS プロバイダーの基礎」を参照してください。

  2. クラス SMS_StateMigrationで AddAssociation メソッドを呼び出します。

次のメソッド例では、ソース コンピューターと参照コンピューターの間に関連付けを追加します。

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

Sub AssociateComputer(connection, referenceComputerResourceId, destinationComputerResourceId)

    Dim stateMigrationClass
    Dim inParams
    Dim outParams

    ' Get the state migration class.
    Set stateMigrationClass = connection.Get("SMS_StateMigration")

    ' Set up the parameters.
    Set inParams = _
      stateMigrationClass.Methods_("AddAssociation").InParameters.SpawnInstance_
    inParams.SourceClientResourceID = referenceComputerResourceId
    inParams.RestoreClientResourceID = destinationComputerResourceId

    ' Call the method.
    Set outParams = _
      connection.ExecMethod( "SMS_StateMigration", "AddAssociation", inParams)

   End Sub
public void AssociateComputer(
    WqlConnectionManager connection,
    int referenceComputerResourceId,
    int destinationComputerResourceId)
{
    try
    {
        // Set up the reference and destination computer in parameters.
        Dictionary<string, object> inParams = new Dictionary<string, object>();
        inParams.Add("SourceClientResourceID", referenceComputerResourceId);
        inParams.Add("RestoreClientResourceID", destinationComputerResourceId);

        // Create the computer association.
       connection.ExecuteMethod("SMS_StateMigration", "AddAssociation", inParams);
    }
    catch (SmsException e)
    {
        Console.WriteLine("failed to make the association" + e.Message);
        throw;
    }
}

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

パラメーター 説明
connection -管理: WqlConnectionManager
- VBScript: SWbemServices
SMS プロバイダーへの有効な接続。
referenceComputerResourceID -管理: Integer
- VBScript: Integer
参照コンピューターのConfiguration Managerリソース識別子。 これは、コンピューター SMS_R_System クラス ResourceId プロパティから使用できます。
destinationComputerResourceID -管理: Integer
- VBScript: Integer
対象コンピューターのConfiguration Managerリソース識別子。 これは、コンピューター SMS_R_System クラス ResourceId プロパティから使用できます。

コードのコンパイル

C# の例には、次のコンパイル要件があります。

名前空間

System

System.Collections.Generic

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

microsoft.configurationmanagement.managementprovider

adminui.wqlqueryengine

堅牢なプログラミング

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

.NET Framework のセキュリティ

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

関連項目

クラス SMS_StateMigration の OS 展開コンピューター管理AddAssociation メソッドSMS_StateMigrationDeleteAssociation メソッドについて