Como configurar configurações de inventário de software

Você define as configurações do Agente cliente do Inventário de Software, em Configuration Manager, modificando as configurações de arquivo de controle de site necessárias.

Para modificar as configurações do Agente cliente do Inventário de Software

  1. Configure uma conexão com o Provedor de SMS.

  2. Faça uma conexão com a seção Agente de Cliente de Inventário de Software do arquivo de controle do site usando a classe SMS_SCI_ClientComp .

  3. Faça loop pela matriz de propriedades disponíveis, fazendo alterações conforme necessário.

  4. Confirme as alterações no arquivo de controle do site.

Exemplo

O exemplo a seguir define as configurações do Agente cliente do Inventário de Software usando a classe SMS_SCI_ClientComp para se conectar ao arquivo de controle do site e alterar propriedades.

Para obter informações sobre como chamar o código de exemplo, consulte Chamando Configuration Manager Snippets de Código.


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;  
    }  
}  

O método de exemplo tem os seguintes parâmetros:

Parâmetro Tipo Descrição
- connection
- swbemServices
-Gerenciado: WqlConnectionManager
- VBScript: SWbemServices
Uma conexão válida com o provedor de SMS.
swbemContext -Vbscript: SWbemContext Um objeto de contexto válido. Para obter mais informações, consulte Como adicionar um qualificador de contexto de Configuration Manager usando o WMI.
siteCode -Gerenciado: String
-Vbscript: String
O código do site.
enableDisableClientAgent -Gerenciado: String
-Vbscript: String
Um valor para habilitar ou desabilitar o agente cliente.

Desabilitado – 0

Habilitado – 1
newInventorySchedule -Gerenciado: String
-Vbscript: String
Um valor para definir o agendamento de inventário.
newScanInterval -Gerenciado: String
-Vbscript: String
Um valor para definir o intervalo de verificação.

Compilando o código

Este exemplo de C# requer:

Namespaces

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Assembly

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Programação robusta

Para obter mais informações sobre o tratamento de erros, consulte Sobre erros de Configuration Manager.

Segurança do .NET Framework

Para obter mais informações sobre como proteger aplicativos Configuration Manager, consulte Configuration Manager administração baseada em função.

Confira também

Sobre Configuration Manager Inventário
Sobre o arquivo de controle de site Configuration Manager
Como ler e gravar no arquivo de controle de site Configuration Manager usando código gerenciado
Como ler e gravar no arquivo de controle de site Configuration Manager usando o WMI
Classe WMI do servidor SMS_SCI_Component
Sobre agendamentosComo Create um token de agendamento