Jak skonfigurować ustawienia spisu oprogramowania
Ustawienia agenta klienta spisu oprogramowania można ustawić w Configuration Manager, modyfikując wymagane ustawienia pliku kontroli lokacji.
Aby zmodyfikować ustawienia agenta klienta spisu oprogramowania
Skonfiguruj połączenie z dostawcą programu SMS.
Nawiązywanie połączenia z sekcją Agent klienta spisu oprogramowania w pliku kontroli lokacji przy użyciu klasy SMS_SCI_ClientComp .
Przeprowadź pętlę przez tablicę dostępnych właściwości, wprowadzając zmiany zgodnie z potrzebami.
Zatwierdź zmiany w pliku kontroli lokacji.
Przykład
W poniższym przykładzie ustawienia agenta klienta spisu oprogramowania są ustawiane przy użyciu klasy SMS_SCI_ClientComp w celu nawiązania połączenia z plikiem kontroli lokacji i zmiany właściwości.
Aby uzyskać informacje na temat wywoływania przykładowego kodu, zobacz Wywoływanie fragmentów kodu 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;
}
}
Przykładowa metoda ma następujące parametry:
Parametr | Wpisać | Opis |
---|---|---|
- connection - swbemServices |
-Zarządzane: WqlConnectionManager - VBScript: SWbemServices |
Prawidłowe połączenie z dostawcą programu SMS. |
swbemContext |
-Vbscript: SWbemContext |
Prawidłowy obiekt kontekstu. Aby uzyskać więcej informacji, zobacz How to Add a Configuration Manager Context Qualifier by Using WMI (Jak dodać kwalifikator kontekstu Configuration Manager przy użyciu usługi WMI). |
siteCode |
-Zarządzane: String -Vbscript: String |
Kod witryny. |
enableDisableClientAgent |
-Zarządzane: String -Vbscript: String |
Wartość umożliwiająca włączenie lub wyłączenie agenta klienta. Wyłączone — 0 Włączone — 1 |
newInventorySchedule |
-Zarządzane: String -Vbscript: String |
Wartość do ustawienia harmonogramu spisu. |
newScanInterval |
-Zarządzane: String -Vbscript: String |
Wartość do ustawienia interwału skanowania. |
Kompilowanie kodu
Ten przykład języka C# wymaga:
Obszary nazw
System
System.collections.generic
System.text
Microsoft. ConfigurationManagement.ManagementProvider
Microsoft. ConfigurationManagement.ManagementProvider.WqlQueryEngine
Zestawu
adminui.wqlqueryengine
microsoft.configurationmanagement.managementprovider
Niezawodne programowanie
Aby uzyskać więcej informacji na temat obsługi błędów, zobacz Informacje o błędach Configuration Manager.
zabezpieczenia .NET Framework
Aby uzyskać więcej informacji na temat zabezpieczania aplikacji Configuration Manager, zobacz Configuration Manager administracja oparta na rolach.
Zobacz też
Informacje o spisie Configuration Manager
Informacje o pliku kontrolki lokacji Configuration Manager
Jak odczytywać i zapisywać w pliku kontroli lokacji Configuration Manager przy użyciu kodu zarządzanego
Jak odczytywać i zapisywać w pliku kontroli lokacji Configuration Manager przy użyciu usługi WMI
SMS_SCI_Component Server WMI Class
Informacje o harmonogramachJak utworzyć token harmonogramu