Udostępnij za pośrednictwem


Jak skonfigurować ustawienia agenta klienta urządzenia przenośnego

Ustawienia agenta klienta urządzenia przenośnego można skonfigurować w Configuration Manager, modyfikując plik kontroli lokacji.

Ważna

Ten artykuł dotyczy tylko starszego klienta urządzenia przenośnego.

Aby skonfigurować ustawienia agenta klienta urządzenia przenośnego

  1. Skonfiguruj połączenie z dostawcą programu SMS.

  2. Nawiązywanie połączenia z sekcją Klient urządzenia w pliku kontroli lokacji SMS_SCI_ClientComp przy użyciu klasy .

  3. Przeprowadź pętlę przez tablicę dostępnych właściwości, wprowadzając zmiany zgodnie z potrzebami.

  4. Zatwierdź zmiany właściwości w pliku kontroli lokacji.

Przykład

Poniższa przykładowa metoda konfiguruje różne ustawienia agenta klienta urządzenia przenośnego SMS_SCI_ClientComp przy użyciu klasy 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 ConfigureMobileDeviceClientAgentSettings(swbemServices,                        _  
                                             swbemContext,                         _  
                                             siteCode,                             _  
                                             newPollIntervalMinutes,               _  
                                             newPollIntervalHours,                 _  
                                             newFailureRetryCount,                 _  
                                             newFailureRetryIntervalMinutes,       _   
                                             newFailureRetryIntervalHours,         _  
                                             newEnableDisableSoftwareDistribution)  

    ' Variables to build poll interval string.  
    ' Note: The sample code only passes in minutes and hours, so setting empty values to use.  
    emptySeconds = "00"  
    emptyDays = "00"  
    emptyMonths = "00"  
    emptyYears = "0000"  

    ' Build newPollInterval string (the format must be "0000-00-00 00:00:00").  
    newPollInterval = emptyYears & "-" & emptyMonths & "-" & emptyDays & " " & newPollIntervalHours & ":" & newPollIntervalMinutes & ":" & emptySeconds  
    newFailureRetryInterval = emptyYears & "-" & emptyMonths & "-" & emptyDays & " " & newFailureRetryIntervalHours & ":" & newFailureRetryIntervalMinutes & ":" & emptySeconds  

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

    Query = "SELECT * FROM SMS_SCI_ClientComp " & _  
    "WHERE ClientComponentName = 'Device Client' " & _  
    "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 property instances.  
        For Each vProperty In SCIComponent.Props  

            ' Setting: Poll Interval  
            If vProperty.PropertyName = "Poll Interval" Then  
                wscript.echo " "  
                wscript.echo vProperty.PropertyName  
                wscript.echo "Current value " &  vProperty.Value2                 

                'Modify the value.  
                vProperty.Value2 = newPollInterval  
                wscript.echo "New value " & newPollInterval  
            End If  

            ' Setting: Failure Retry Count  
            If vProperty.PropertyName = "Failure Retry Count" Then  
                wscript.echo " "  
                wscript.echo vProperty.PropertyName  
                wscript.echo "Current value " &  vProperty.Value                 

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

            ' Setting: Failure Retry Interval  
            If vProperty.PropertyName = "Failure Retry Interval" Then  
                wscript.echo " "  
                wscript.echo vProperty.PropertyName  
                wscript.echo "Current value " &  vProperty.Value2                 

                ' Modify the value.  
                vProperty.Value2 = newFailureRetryInterval  
                wscript.echo "New value " & newFailureRetryInterval  
            End If  

            ' Setting: Enable Software Dist  
            If vProperty.PropertyName = "Enable Software Dist" Then  
                wscript.echo " "  
                wscript.echo vProperty.PropertyName  
                wscript.echo "Current value " &  vProperty.Value2                 

                ' Modify the value.  
                vProperty.Value2 = newEnableDisableSoftwareDistribution  
                wscript.echo "New value " & newEnableDisableSoftwareDistribution  
            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 ConfigureMobileDeviceClientAgentSettings(WqlConnectionManager connection,  
                                                     string siteCode,  
                                                     string newPollIntervalMinutes,  
                                                     string newPollIntervalHours,  
                                                     string newFailureRetryCount,  
                                                     string newFailureRetryIntervalMinutes,  
                                                     string newFailureRetryIntervalHours,  
                                                     bool newEnableDisableSoftwareDistribution)  
{  

    // Define variables to build poll interval string.  
    // Note: The example code only passes in minutes and hours, so this sets empty values to use.  
    string emptyDays = "00";  
    string emptyMonths = "00";  
    string emptyYears = "0000";  
    string emptySeconds = "00";  

    // Build newPollInterval and newFailureRetryInterval strings (the format must be "0000-00-00 00:00:00").  
    string newPollInterval = emptyYears + "-" + emptyMonths + "-" + emptyDays + " " + newPollIntervalHours + ":" + newPollIntervalMinutes + ":" + emptySeconds;  
    string newFailureRetryInterval = emptyYears + "-" + emptyMonths + "-" + emptyDays + " " + newFailureRetryIntervalHours + ":" + newFailureRetryIntervalMinutes + ":" + emptySeconds;  

    try  
    {  
        IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_ClientComp.FileType=1,ItemType='Client Component',SiteCode='" + siteCode + "',ItemName='Device Client'");  

        // Loop through the array of embedded properties.  
        foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)  
        {  
            // Create temporary working copy of embedded properties.  
            Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties;  

            // Setting: Poll Interval.  
            if (kvp.Value.PropertyList["PropertyName"] == "Poll Interval")  
            {  
                Console.WriteLine();  
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
                Console.WriteLine("Current value: " + embeddedProperties[kvp.Value.PropertyList["PropertyName"]]["Value2"].StringValue);  

                // Change value using the newPollInterval value passed in.   
                embeddedProperties[kvp.Value.PropertyList["PropertyName"]]["Value2"].StringValue = newPollInterval;  
                Console.WriteLine("New value    : " + newPollInterval);  
            }  

            // Setting: Failure Retry Count.  
            if (kvp.Value.PropertyList["PropertyName"] == "Failure Retry Count")  
            {  
                Console.WriteLine();  
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
                Console.WriteLine("Current value: " + embeddedProperties[kvp.Value.PropertyList["PropertyName"]]["Value"].StringValue);  

                // Change value using the newFailureRetryCount value passed in.   
                embeddedProperties[kvp.Value.PropertyList["PropertyName"]]["Value"].StringValue = newFailureRetryCount;  
                Console.WriteLine("New value    : " + newFailureRetryCount);  
            }  

            // Setting: Failure Retry Interval.  
            if (kvp.Value.PropertyList["PropertyName"] == "Failure Retry Interval")  
            {  
                Console.WriteLine();  
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
                Console.WriteLine("Current value: " + embeddedProperties[kvp.Value.PropertyList["PropertyName"]]["Value2"].StringValue);  

                // Change value using the newFailureRetryInterval value passed in.   
                embeddedProperties[kvp.Value.PropertyList["PropertyName"]]["Value2"].StringValue = newFailureRetryInterval;  
                Console.WriteLine("New value    : " + newFailureRetryInterval);  
            }  

            // Setting: Enable Software Dist.  
            if (kvp.Value.PropertyList["PropertyName"] == "Enable Software Dist")  
            {  
                Console.WriteLine();  
                Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
                Console.WriteLine("Current value: " + embeddedProperties[kvp.Value.PropertyList["PropertyName"]]["Value2"].StringValue);  

                // Change value using the newEnableDisableSoftwareDistribution value passed in.   
                embeddedProperties[kvp.Value.PropertyList["PropertyName"]]["Value2"].BooleanValue = newEnableDisableSoftwareDistribution;  
                Console.WriteLine("New value    : " + newEnableDisableSoftwareDistribution);  
            }  

            // 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.
newPollInterval -Zarządzane: String
-Vbscript: String
Interwał, który klient próbuje skontaktować się z serwerem.

Format ciągu musi być następujący:

Years-months-days hours:minutes:seconds

"0000-00-00 00:00:00"
newPollIntervalMinutes -Zarządzane: String
-Vbscript: String
Wartość reprezentująca minuty newPollInterval ciągu.
newPollIntervalHours -Zarządzane: String
-Vbscript: String
Wartość reprezentująca godziny newPollInterval ciągu.
newFailureRetryCount -Zarządzane: String
-Vbscript: String
Wartość reprezentująca godziny newPollInterval ciągu.
newFailureRetryIntervalMinutes -Zarządzane: String
-Vbscript: String
Wartość reprezentująca minuty newFailureRetryInterval ciągu.
newFailureRetryIntervalHours -Zarządzane: String
-Vbscript: String
Wartość reprezentująca godziny newFailureInterval ciągu.
newEnableDisableSoftwareDistribution -Zarządzane: Boolean
-Vbscript: Boolean
Wartość, która włącza lub wyłącza dystrybucję oprogramowania.

Włączone = true

Wyłączone = false

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 konfiguracji i konfiguracji Aktualizacje oprogramowania
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