Dela via


Så här konfigurerar du klientagentinställningar för programdistribution annonserade program

I Configuration Manager underhåller platskontrollfilen konfigurationen för platsens konfiguration. Det här avsnittet visar hur du konfigurerar klientagentinställningar för programdistribution annonserade program i platskontrollfilen. Mer information om att läsa från och skriva till platskontrollfilen finns i Om platskontrollfilen.

Försiktighet

Du bör ha erfarenhet av att hantera en platskonfiguration innan du använder SMS-providerklasserna för att ändra platskonfigurationen. Du bör vara försiktig eller undvika att använda klasserna SMS_SCI_FileDefinition och SMS_SCI_SiteDefinition helt och hållet. De här klasserna hanterar själva platskontrollfilen. Du kan orsaka betydande skador på en webbplats genom att ändra vissa konfigurerbara objekt.

Så här konfigurerar du klientagentinställningar

  1. Konfigurera en anslutning till SMS-providern. Mer information finns i grunderna för SMS-provider.

  2. Upprätta en anslutning till klientkomponentavsnittet för programdistribution i platskontrollfilen med hjälp av klassen SMS_SCI_ClientComp .

  3. Gå igenom matrisen med tillgängliga egenskaper och gör ändringar efter behov.

  4. Checka in egenskapsändringarna i platskontrollfilen.

Exempel

Följande exempel frågar efter specifika objekt i avsnittet klientkomponent för programvarudistribution i platskontrollfilen och ändrar de specifika klientagentinställningarna.

Information om hur du anropar exempelkoden finns i Anropa Configuration Manager kodfragment.


Sub ConfigureClientAgentSettings(swbemServices, swbemContext, siteToChange, enableDisableSWDClientAgent, enableDisableRequestUserPolicy, setPolicyRefreshInterval, enableDisableVisibleSignalOnAvailable, enableDisableAudibleSignalonAvailable,enableDisableCountdownSignal,setCountdownMinutes, enableDisableShowIcon)  

    ' Load site control file and get SWD client component section.  
    swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteToChange & """", "Refresh", , , swbemContext  
    Set objSWbemInst = swbemServices.Get("SMS_SCI_ClientComp.Filetype=1,Itemtype='Client Component',Sitecode='" & siteToChange & "',ItemName='Software Distribution'", , swbemContext)  

    ' Display SWD client agent settings before change.  
    Wscript.Echo " "  
    Wscript.Echo "Before Change"  
    Wscript.Echo "-------------"  

    Wscript.Echo " "  
    Wscript.Echo objSWbemInst.ClientComponentName  
    Wscript.Echo "Current value: " & objSWbemInst.Flags & " (0 = Disabled, 1 = Enabled)"  
    Wscript.Echo " "  
    objSWbemInst.Flags = enableDisableSWDClientAgent  

    ' Enumerate though the property array, but display only the properties that we're specifically interested in.  
    ' Note: A list of all properties could be generated by just using the following code:  
    '     PropertyArray = objSwbemInst.props  
    '     For i = 0 to ubound(PropertyArray)  
    '        Wscript.Echo PropertyArray(i).PropertyName  
    '        Wscript.Echo "Current value: " & PropertyArray(i).Value  
    '     Next  

    PropertyArray = objSwbemInst.props  
    For i = 0 to ubound(PropertyArray)  

        ' Client settings: Allow user targeted advertisement requests.  
        If PropertyArray(i).PropertyName = "Request User Policy" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
            PropertyArray(i).Value = enableDisableRequestUserPolicy   
        End If  

        ' Client settings: Policy polling interval (minutes).  
        If PropertyArray(i).PropertyName = "Policy Refresh Interval" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
            PropertyArray(i).Value = setPolicyRefreshInterval   
        End If  

        ' When new advertised programs are available: Display a notification message.  
        If PropertyArray(i).PropertyName = "Visible Signal on Available" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
            PropertyArray(i).Value = enableDisableVisibleSignalOnAvailable   
        End If  

        ' When new advertised programs are available: Play a sound.  
        If PropertyArray(i).PropertyName = "Audible Signal on Available" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
            PropertyArray(i).Value = enableDisableAudibleSignalonAvailable   
        End If  

        ' When a scheduled program is about to run: Provide a countdown.  
        If PropertyArray(i).PropertyName = "Countdown Signal" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
            PropertyArray(i).Value = enableDisableCountdownSignal   
        End If  

        ' Countdown length (minutes).  
        If PropertyArray(i).PropertyName = "Countdown Minutes" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
            PropertyArray(i).Value = setCountdownMinutes   
        End If  

        ' Show advertised program notification icons in the notification area.  
        If PropertyArray(i).PropertyName = "Show Icon" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
            PropertyArray(i).Value = enableDisableShowIcon   
        End If  
    Next  

    ' Save new client agent settings.  
    objSWbemInst.Put_ , swbemContext  
    swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteToChange & """", "Commit", , , swbemContext  

    ' Refresh in-memory copy of the site control file and get the SWD client component section.  
    swbemServices.ExecMethod "SMS_SiteControlFile.Filetype=1,Sitecode=""" & siteToChange & """", "Refresh", , , swbemContext  
    Set objSWbemInst = swbemServices.Get("SMS_SCI_ClientComp.Filetype=1,Itemtype='Client Component',Sitecode='" & siteToChange & "',ItemName='Software Distribution'", , swbemContext)  

    ' Display SWD client agent settings after change.  

    Wscript.Echo " "  
    Wscript.Echo "After Change"  
    Wscript.Echo "------------"  

    Wscript.Echo " "  
    Wscript.Echo objSWbemInst.ClientComponentName  
    Wscript.Echo "Current value: " & objSWbemInst.Flags & " (0 = Disabled, 1 = Enabled)"  
    Wscript.Echo " "  

    PropertyArray = objSwbemInst.props  
    For i = 0 to ubound(PropertyArray)  

        ' Client settings: Allow user targeted advertisement requests.  
        If PropertyArray(i).PropertyName = "Request User Policy" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
        End If  

        ' Client settings: Policy polling interval (minutes).  
        If PropertyArray(i).PropertyName = "Policy Refresh Interval" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
        End If  

        ' When new advertised programs are available: Display a notification message.  
        If PropertyArray(i).PropertyName = "Visible Signal on Available" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
        End If  

        ' When new advertised programs are available: Play a sound.  
        If PropertyArray(i).PropertyName = "Audible Signal on Available" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
        End If  

        ' When a scheduled program is about to run: Provide a countdown.  
        If PropertyArray(i).PropertyName = "Countdown Signal" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
        End If  

        ' Countdown length (minutes).  
        If PropertyArray(i).PropertyName = "Countdown Minutes" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
        End If  

        ' Show advertised program notification icons in the notification area.  
        If PropertyArray(i).PropertyName = "Show Icon" Then  
            Wscript.Echo PropertyArray(i).PropertyName  
            Wscript.Echo "Current value: " & PropertyArray(i).Value  
            Wscript.Echo " "  
        End If  
    Next  

End Sub  
public void ConfigureSWDClientAgentSettings(WqlConnectionManager connection, string siteCode, string enableDisableSWDClientAgent, string enableDisableRequestUserPolicy, string setPolicyRefreshInterval, string enableDisableVisibleSignalOnAvailable, string enableDisableAudibleSignalonAvailable, string enableDisableCountdownSignal, string setCountdownMinutes, string enableDisableShowIcon)  
{  
try  
{  
    IResultObject siteDefinition = connection.GetInstance(@"SMS_SCI_ClientComp.FileType=1,ItemType='Client Component',SiteCode='" + siteCode + "',ItemName='Software Distribution'");  

    Console.WriteLine();  
    Console.WriteLine("Before Change");  
    Console.WriteLine("-------------");  

    // Enable software distribution to clients.  
    // Set SWD client agent by setting flags value to  0 or 1 using the EnableDisableSWDClientAgent variable.  
    Console.WriteLine("Software Distribution Client Agent");  
    Console.WriteLine("Current value: " + siteDefinition["Flags"].StringValue + " (0 = Disabled, 1 = Enabled)");  
    siteDefinition["Flags"].StringValue = enableDisableSWDClientAgent;  

    foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition.EmbeddedProperties)  
    {  
        Dictionary<string, IResultObject> embeddedProperties = siteDefinition.EmbeddedProperties; // temp copy  

        // Client settings: Allow user targeted advertisement requests.  
        if (kvp.Value.PropertyList["PropertyName"] == "Request User Policy")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Request User Policy"]["Value"].StringValue);  
            embeddedProperties["Request User Policy"]["Value"].StringValue = enableDisableRequestUserPolicy;  
        }  

        // Client settings: Policy polling interval (minutes).  
        if (kvp.Value.PropertyList["PropertyName"] == "Policy Refresh Interval")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Policy Refresh Interval"]["Value"].StringValue);  
            embeddedProperties["Policy Refresh Interval"]["Value"].StringValue = setPolicyRefreshInterval;  
        }  

        // When new advertised programs are available: Display a notification message.  
        if (kvp.Value.PropertyList["PropertyName"] == "Visible Signal on Available")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Visible Signal on Available"]["Value"].StringValue);  
            embeddedProperties["Visible Signal on Available"]["Value"].StringValue = enableDisableVisibleSignalOnAvailable;  
        }  

        // When new advertised programs are available: Play a sound.  
        if (kvp.Value.PropertyList["PropertyName"] == "Audible Signal on Available")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Audible Signal on Available"]["Value"].StringValue);  
            embeddedProperties["Audible Signal on Available"]["Value"].StringValue = enableDisableAudibleSignalonAvailable;                      
        }  

        // When a scheduled program is about to run: Provide a countdown.  
        if (kvp.Value.PropertyList["PropertyName"] == "Countdown Signal")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Countdown Signal"]["Value"].StringValue);  
            embeddedProperties["Countdown Signal"]["Value"].StringValue = enableDisableCountdownSignal;  
        }  

        // Countdown length (minutes).  
        if (kvp.Value.PropertyList["PropertyName"] == "Countdown Minutes")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Countdown Minutes"]["Value"].StringValue);  
            embeddedProperties["Countdown Minutes"]["Value"].StringValue = setCountdownMinutes;  
        }  

        // Show advertised program notification icons in the notification area.  
        if (kvp.Value.PropertyList["PropertyName"] == "Show Icon")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Show Icon"]["Value"].StringValue);  
            embeddedProperties["Show Icon"]["Value"].StringValue = enableDisableShowIcon;  
        }  

        // Store the settings that have changed.  
        siteDefinition.EmbeddedProperties = embeddedProperties;  
    }  

    // Save the settings.   
    siteDefinition.Put();  

    // Verify change by reconnecting and getting the value again.  
    IResultObject siteDefinition2 = connection.GetInstance(@"SMS_SCI_ClientComp.FileType=1,ItemType='Client Component',SiteCode='" + siteCode + "',ItemName='Software Distribution'");  

    Console.WriteLine();  
    Console.WriteLine("After Change");  
    Console.WriteLine("-------------");  

    // Enable software distribution to clients.  
    Console.WriteLine("Software Distribution Client Agent");  
    Console.WriteLine("Current value: " + siteDefinition2["Flags"].StringValue + " (0 = Disabled, 1 = Enabled)");  

    foreach (KeyValuePair<string, IResultObject> kvp in siteDefinition2.EmbeddedProperties)  
    {  
        Dictionary<string, IResultObject> embeddedProperties = siteDefinition2.EmbeddedProperties; // temp copy  

        // Client settings: Allow user targeted advertisement requests.  
        if (kvp.Value.PropertyList["PropertyName"] == "Request User Policy")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Request User Policy"]["Value"].StringValue);  
        }  

        // Client settings: Policy polling interval (minutes).  
        if (kvp.Value.PropertyList["PropertyName"] == "Policy Refresh Interval")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Policy Refresh Interval"]["Value"].StringValue);  
        }  

        // When new advertised programs are available: Display a notification message.  
        if (kvp.Value.PropertyList["PropertyName"] == "Visible Signal on Available")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Visible Signal on Available"]["Value"].StringValue);  
        }  

        // When new advertised programs are available: Play a sound.  
        if (kvp.Value.PropertyList["PropertyName"] == "Audible Signal on Available")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Audible Signal on Available"]["Value"].StringValue);  
        }  

        // When a scheduled program is about to run: Provide a countdown.  
        if (kvp.Value.PropertyList["PropertyName"] == "Countdown Signal")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Countdown Signal"]["Value"].StringValue);  
        }  

        // Countdown length (minutes).  
        if (kvp.Value.PropertyList["PropertyName"] == "Countdown Minutes")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Countdown Minutes"]["Value"].StringValue);  
        }  

        // Show advertised program notification icons in the notification area.  
        if (kvp.Value.PropertyList["PropertyName"] == "Show Icon")  
        {  
            Console.WriteLine(kvp.Value.PropertyList["PropertyName"]);  
            Console.WriteLine("Current value: " + embeddedProperties["Show Icon"]["Value"].StringValue);  
        }  
    }  

    Console.WriteLine(" ");  
}  

    catch (SmsException ex)  
    {  
        Console.WriteLine("Failed. Error: " + ex.InnerException.Message);  
        throw;  
    }  

}  

Exempelmetoden har följande parametrar:

Parameter Typ Beskrivning
connection

swbemServices
-Hanterade: WqlConnectionManager
– VBScript: SWbemServices
En giltig anslutning till SMS-providern.
swbemContext -Vbscript: SWbemContext Ett giltigt kontextobjekt. Mer information finns i How to Add a Configuration Manager Context Qualifier by Using WMI (Lägga till en Configuration Manager kontextkvalificerare med hjälp av WMI).
siteCode

siteToChange
-Hanterade: String
-Vbscript: String
Platskoden.
enableDisableSWDClientAgent -Hanterade: String
-Vbscript: String
Flagga för att aktivera eller inaktivera klientagenten.
setPolicyRefreshInterval -Hanterade: String
-Vbscript: String
Intervall för principsökning i minuter.
enableDisableRequestUserPolicy -Hanterade: String
-Vbscript: String
Flagga för att aktivera eller inaktivera riktade annonsbegäranden.
enableDisableVisibleSignalOnAvailable -Hanterade: String
-Vbscript: String
Flagga för att aktivera eller inaktivera visning av ett meddelande när nya annonserade program är tillgängliga.
enableDisableAudibleSignalonAvailable -Hanterade: String
-Vbscript: String
Flagga för att aktivera eller inaktivera ett hörbart meddelande när nya annonserade program är tillgängliga.
enableDisableCountdownSignal -Hanterade: String
-Vbscript: String
Flagga för att aktivera eller inaktivera en nedräkning när ett schemalagt program är på väg att köras.
setCountdownMinutes -Hanterade: String
-Vbscript: String
Nedräkningslängd, i minuter.
enableDisableShowIcon -Hanterade: String
-Vbscript: String
Flagga för att aktivera eller inaktivera visning av ikoner för annonserade programmeddelanden i meddelandefältet.

Kompilera koden

C#-exemplet kräver:

Namnområden

System

System.Collections.Generic

System.ComponentModel

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Församlingen

adminui.wqlqueryengine

microsoft.configurationmanagement.managementprovider

Robust programmering

Mer information om felhantering finns i Om Configuration Manager fel.

.NET Framework Säkerhet

Mer information om hur du skyddar Configuration Manager program finns i Configuration Manager rollbaserad administration.

Se även

Översikt över programvarudistributionOm installation och konfiguration av programvarudistributionOm Configuration Manager platskontrollfil
Läsa och skriva till Configuration Manager platskontrollfil med hjälp av hanterad kod
Läsa och skriva till Configuration Manager platskontrollfil med hjälp av WMI
SMS_SCI_Component, serverns WMI-klass