Udostępnij za pośrednictwem


Jak utworzyć token harmonogramu

Token harmonogramu można utworzyć w Configuration Manager przez utworzenie i wypełnienie wystąpienia odpowiedniej SMS_ST_ klasy tokenu harmonogramu. SMS_ST klasy harmonogramu są klasami podrzędnymi SMS_ScheduleToken klasy i obsługują planowanie zdarzeń o różnych częstotliwościach, takich jak codziennie, co tydzień i co miesiąc.

Klasa SMS_ScheduleMethods Instrumentacja zarządzania windows (WMI) oraz odpowiednie metody ReadFromString i WriteToString służą do dekodowania i kodowania tokenów harmonogramu do i z ciągu interwału. Ciągów interwału można następnie użyć do ustawiania właściwości harmonogramu podczas definiowania lub modyfikowania obiektów. Przykład można znaleźć w temacie How to Create a Maintenance Window for a Collection (Jak utworzyć okno konserwacji dla kolekcji), w ServiceWindowSchedules którym skonfigurowano właściwość.

Aby utworzyć token harmonogramu i przekonwertować go na ciąg interwału

  1. Utwórz obiekt tokenu harmonogramu przy użyciu jednej z klas podrzędnych SMS_ScheduleToken . W tym przykładzie użyto klasy SMS_ST_RecurInterval .

  2. Wypełnij właściwości nowego obiektu tokenu harmonogramu.

  3. Konwertuj obiekt tokenu harmonogramu na ciąg interwału SMS_ScheduleMethods przy użyciu klasy i WriteToString metody.

  4. Użyj ciągu interwału, aby wypełnić właściwości harmonogramu obiektu zgodnie z potrzebami.

Przykład

Poniższa przykładowa metoda pokazuje, jak utworzyć token harmonogramu przez utworzenie i wypełnienie wystąpienia klasy tokenu harmonogramu SMS_ST_RecurInterval . Ponadto w przykładzie pokazano, jak przekonwertować harmonogram na ciąg interwału SMS_ScheduleMethods przy użyciu klasy i WriteToString metody.

Aby uzyskać informacje na temat wywoływania przykładowego kodu, zobacz Wywoływanie fragmentów kodu Configuration Manager.


Sub CreateDailyRecurringScheduleString(connection,   _
                                       hourDuration, _
                                       daySpan,      _
                                       startTime,    _
                                       isGmt)

    ' Create a new recurring interval schedule object.
    ' Note: There are several types of schedule classes available, each defines a different type of schedule.
    Set recurInterval = connection.Get("SMS_ST_RecurInterval").SpawnInstance_

    ' Populate the schedule properties.
    recurInterval.DayDuration = 0
    recurInterval.HourDuration = hourDuration
    recurInterval.MinuteDuration = 0
    recurInterval.DaySpan = daySpan
    recurInterval.HourSpan = 0
    recurInterval.MinuteSpan = 0
    recurInterval.StartTime = startTime
    recurInterval.IsGMT = isGmt

    ' Call WriteToString method to decode the schedule token.
    ' Note: The initial parameter of the WriteToString method requires an array.
    Set clsScheduleMethod = connection.Get("SMS_ScheduleMethods")
    clsScheduleMethod.WriteToString Array(recurInterval), scheduleString

    ' Output schedule token as an interval string.
    WScript.Echo "Schedule Token Interval String: " & scheduleString

End Sub

public void CreateDailyRecurringScheduleToken(WqlConnectionManager connection,
                                              int hourDuration,
                                              int daySpan,
                                              string startTime,
                                              bool isGmt)
{
    try
    {
        // Create a new recurring interval schedule object.
        // Note: There are several types of schedule classes available, each defines a different type of schedule.
        IResultObject recurInterval = connection.CreateEmbeddedObjectInstance("SMS_ST_RecurInterval");

        // Populate the schedule properties.
        recurInterval["DayDuration"].IntegerValue = 0;
        recurInterval["HourDuration"].IntegerValue = hourDuration;
        recurInterval["MinuteDuration"].IntegerValue = 0;
        recurInterval["DaySpan"].IntegerValue = daySpan;
        recurInterval["HourSpan"].IntegerValue = 0;
        recurInterval["MinuteSpan"].IntegerValue = 0;
        recurInterval["StartTime"].StringValue = startTime;
        recurInterval["IsGMT"].BooleanValue = isGmt;

        // Creating array to use as a parameters for the WriteToString method.
        List<IResultObject> scheduleTokens = new List<IResultObject>();
        scheduleTokens.Add(recurInterval);

        // Creating dictionary object to pass parameters to the WriteToString method.
        Dictionary<string, object> inParams = new Dictionary<string, object>();
        inParams["TokenData"] = scheduleTokens;

        // Initialize the outParams object.
        IResultObject outParams = null;

        // Call WriteToString method to decode the schedule token.
        outParams = connection.ExecuteMethod("SMS_ScheduleMethods", "WriteToString", inParams);

        // Output schedule token as an interval string.
        // Note: The return value for this method is always 0, so this check is just best practice.
        if (outParams["ReturnValue"].IntegerValue == 0)
        {
            Console.WriteLine("Schedule Token Interval String: " + outParams["StringData"].StringValue);
        }
    }
    catch (SmsException ex)
    {
        Console.WriteLine("Failed. Error: " + ex.InnerException.Message);
    }
}

Przykładowa metoda ma następujące parametry:

Parametr Wpisać Opis
connection -Zarządzane: WqlConnectionManager
- VBScript: SWbemServices
Prawidłowe połączenie z dostawcą programu SMS.
hourDuration -Zarządzane: Integer
- VBScript: Integer
Liczba godzin, w których odbywa się zaplanowana akcja. Dozwolone wartości znajdują się w zakresie od 0 do 23. Wartość domyślna to 0, co oznacza brak czasu trwania.
daySpan -Zarządzane: Integer
- VBScript: Integer
Liczba dni obejmujących interwały harmonogramu. Dozwolone wartości znajdują się w zakresie od 0 do 31. Wartość domyślna to 0.
startTime — Zarządzane: String (DateTime)
- VBScript: String (DateTime)
Data i godzina wykonania zaplanowanej akcji. Wartość domyślna to "19700201000000.000000+***". Jest to format, w którym są przechowywane wartości CIM DATETIME (WMI).
isGmt -Zarządzane: Boolean
- VBScript: Boolean
true jeśli czas znajduje się w uniwersalnym czasie koordynowanym (UTC). Wartość domyślna to false, dla czasu lokalnego.

Kompilowanie kodu

Przykład języka C# ma następujące wymagania dotyczące kompilacji:

Przestrzenie nazw

System

System.Collections.Generic

System.Text

Microsoft.ConfigurationManagement.ManagementProvider

Microsoft.ConfigurationManagement.ManagementProvider.WqlQueryEngine

Montaż

microsoft.configurationmanagement.managmentprovider

adminui.wqlqueryengine

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ż

Configuration Manager Software Development KitSMS_ST_NonRecurring Server WMI ClassSMS_ST_RecurInterval Server WMI ClassSMS_ST_RecurMonthlyByDate Server WMI ClassSMS_ST_RecurMonthlyByWeekday Server WMI ClassSMS_ST_RecurWeekly Server WMI ClassSMS_ScheduleMethods Server WMI ClassReadFromString Method in Class SMS_ScheduleMethodsWriteToString, metoda w klasie SMS_ScheduleMethods