ソフトウェア インベントリ クライアント エージェントの設定をConfiguration Managerで設定するには、必要なサイト コントロール ファイルの設定を変更します。
ソフトウェア インベントリ クライアント エージェントの設定を変更するには
SMS プロバイダーへの接続を設定します。
SMS_SCI_ClientComp クラスを使用して、サイト コントロール ファイルの [ソフトウェア インベントリ クライアント エージェント] セクションに接続します。
使用可能なプロパティの配列をループして、必要に応じて変更を加えます。
サイト コントロール ファイルに変更をコミットします。
例
次の例では、 SMS_SCI_ClientComp クラスを使用してサイト コントロール ファイルに接続し、プロパティを変更することで、ソフトウェア インベントリ クライアント エージェントの設定を設定します。
サンプル コードの呼び出しについては、「Configuration Manager コード スニペットの呼び出し」を参照してください。
Sub ConfigureSoftwareInventoryClientAgentSettings(swbemServices, _
swbemContext, _
siteCode, _
enableDisableClientAgent, _
newInventorySchedule)
' Load site control file and get the SMS_SCI_ClientComp section.
swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteCode & """", "Refresh", , , swbemContext
Query = "SELECT * FROM SMS_SCI_ClientComp " & _
"WHERE ClientComponentName = 'Software Inventory Agent' " & _
"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
' Set the client agent by setting the Flags value to 0 or 1 using the enableDisableClientAgent variable.
wscript.echo " "
wscript.echo "Software Inventory Agent"
wscript.echo "Current value " & SCIComponent.Flags
' Modify the value.
SCIComponent.Flags = enableDisableClientAgent
wscript.echo "New value " & enableDisableClientAgent
'Loop through the array of embedded SMS_EmbeddedProperty instances.
For Each vProperty In SCIComponent.Props
' Setting: Inventory Schedule
If vProperty.PropertyName = "Inventory Schedule" Then
wscript.echo " "
wscript.echo vProperty.PropertyName
wscript.echo "Current value " & vProperty.Value2
'Modify the value.
vProperty.Value2 = newInventorySchedule
wscript.echo "New value " & newInventorySchedule
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 ConfigureSoftwareInventoryClientAgentSettings(WqlConnectionManager connection,
string siteCode,
string enableDisableClientAgent,
string newInventorySchedule)
{
try
{
IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_ClientComp.FileType=1,ItemType='Client Component',SiteCode='" + siteCode + "',ItemName='Software Inventory Agent'");
// Setting: Enable Client Agent
// Enable or disable the client agent by setting the Flags value to 0 or 1 using the enableDisableClientAgent variable.
Console.WriteLine();
Console.WriteLine("Software Update Client Agent");
Console.WriteLine("Current value: " + siteDefinition["Flags"].StringValue);
// Change value using the enableDisableSUMClientAgent value passed in.
siteDefinition["Flags"].StringValue = enableDisableClientAgent;
Console.WriteLine("New value : " + enableDisableClientAgent);
foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)
{
// Create temporary working copy of embedded properties.
Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties;
// Setting: Inventory Schedule
if (kvp.Value.PropertyList["PropertyName"] == "Inventory Schedule")
{
Console.WriteLine();
Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);
Console.WriteLine("Current value: " + embeddedProperties[kvp.Value.PropertyList["PropertyName"]]["Value2"].StringValue);
// Change value using the newEvaluationSchedule value passed in.
embeddedProperties["Inventory Schedule"]["Value2"].StringValue = newInventorySchedule;
Console.WriteLine("New value : " + newInventorySchedule);
}
// 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 |
サイト コード。 |
enableDisableClientAgent |
-管理: String -Vbscript: String |
クライアント エージェントを有効または無効にする値。 無効 - 0 有効 - 1 |
newInventorySchedule |
-管理: String -Vbscript: String |
インベントリ スケジュールを設定する値。 |
newScanInterval |
-管理: String -Vbscript: String |
スキャン間隔を設定する値。 |
コードのコンパイル
この 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について
マネージド コードを使用してConfiguration Manager サイト コントロール ファイルの読み取りと書き込みを行う方法
WMI を使用してConfiguration Manager サイト コントロール ファイルの読み取りと書き込みを行う方法
SMS_SCI_Component サーバー WMI クラス
スケジュールについて スケジュールトークンをCreateする方法