SystemUpdateManager 클래스

정의

SystemUpdateManager를 사용하면 시스템 업데이트를 대화형으로 제어할 수 있습니다.

public ref class SystemUpdateManager abstract sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.System.SystemManagementContract, 393216)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class SystemUpdateManager final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.System.SystemManagementContract), 393216)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public static class SystemUpdateManager
Public Class SystemUpdateManager
상속
Object Platform::Object IInspectable SystemUpdateManager
특성

Windows 요구 사항

디바이스 패밀리
Windows 10, version 1809 (10.0.17763.0에서 도입되었습니다.)
API contract
Windows.System.SystemManagementContract (v6.0에서 도입되었습니다.)

예제

SystemUpdateManager 샘플 코드

설명

SystemUpdateFlow

시스템 업데이트 프로세스의 상태는 다음과 같습니다.

  1. 탐지. 업데이트 패키지를 사용할 수 있는지 확인합니다.
  2. 다운로드 서버에서 업데이트 패키지를 다운로드합니다.
  3. 스테이지. 업데이트 패키지의 압축을 풀고 나중에 커밋되도록 스테이징합니다.
  4. 업데이트 OS로 다시 부팅할 때까지 기다립니다. OS 업데이트는 OS 변경 내용이 커밋되는 동안 Windows 10 IoT Core 기어를 표시합니다.
  5. 커밋 시스템 업데이트 변경 내용이 커밋되는 동안 기어를 표시하는 업데이트 OS로 부팅합니다.
  6. 업데이트된 기본 OS로 다시 부팅합니다. 이 시점에서 업데이트 프로세스가 완료되었습니다.

업데이트 패키지 설치에는 파일 및 설정을 스테이징 영역으로 추출한 다음 나중에 스테이징된 변경 내용을 커밋하여 업데이트 패키지를 준비하는 것이 포함됩니다. 커밋 단계가 시작되면 업데이트 패키지를 Windows 10 IoT Core 롤백할 수 없습니다. 스테이징된 커밋되지 않은 업데이트 패키지는 업데이트를 취소하여 필요한 경우 삭제할 수 있습니다. 커밋 프로세스가 시작되면 중단될 수 없습니다.

자동 업데이트 프로세스는 정책에 의해 제어됩니다. OEM은 MDM 또는 DUC(디바이스 업데이트 센터)와 같은 정책 관리자를 통해 정책을 제어할 수 있습니다.

대화형 업데이트 프로세스 세션은 디바이스 사용자가 제어합니다. 자동 업데이트 프로세스를 연기하는 정책은 대화형 업데이트 프로세스 세션 중에 재정의될 수 있습니다. 예를 들어 사용자는 업데이트 패키지를 검색하고 자동 업데이트 프로세스 세션이 현재 정책에 의해 이러한 작업을 수행하지 못하도록 차단될 때 대화형 프로세스 세션으로 다운로드할 수 있습니다. 대화형 업데이트 프로세스는 업데이트 패키지를 스테이징할 수도 있습니다. 업데이트 패키지 준비는 패키지의 압축을 풀고 커밋할 패키지의 파일 및 설정을 준비합니다.

업데이트 패키지가 다운로드 및 스테이징되면 업데이트 OS로 다시 부팅하고 업데이트 패키지를 커밋하여 개발자가 대화형 업데이트 프로세스를 계속 진행할 수 있습니다. 업데이트 OS는 업데이트 패키지를 커밋하는 용도로만 사용할 수 있는 매우 작은 OS입니다. Windows 10 IoT Core OS 업데이트는 움직이는 기어가 있는 화면을 표시합니다. 업데이트 OS로 다시 부팅은 사용자 입력에 대한 응답 또는 단일 용도 디바이스의 비즈니스 논리의 일부로 수행할 수 있습니다. OS 업데이트를 진행하려면 RebootToCompleteInstall을 호출해야 합니다. 전원을 켜고 끄거나 대체 API를 사용하여 디바이스를 다시 부팅해도 아무런 효과가 없습니다. 또는 개발자가 현재 정책에 의해 구성된 다음 예약된 자동 업데이트 프로세스 다시 부팅 기간(예: 활성 시간 외)까지 기다리도록 선택할 수 있습니다.

설치하기 전에

SystemUpdateManager API를 사용하기 전에 애플리케이션은 SystemManagementContract 6.0이 있는지 확인해야 합니다.

if (!ApiInformation.IsApiContractPresent("Windows.System.SystemManagementContract", 6, 0))
{
    // SystemUpdateManager was first implemented in SystemManagementContract 6.0
    VisualStateManager.GoToState(this, "NotSupported", false);
    UpdateStateTextBlock.Text = "Windows.System.SystemManagementContract 6.0 not found";
}

다음으로 애플리케이션은 현재 버전의 Windows에서 SystemUpdateManager 가 지원되는지 확인해야 합니다.

else if (!SystemUpdateManager.IsSupported())
{
    // The API must be supported by the current edition of Windows
    // This can also return false if the application doesn't have the systemManagement capability
    VisualStateManager.GoToState(this, "NotSupported", false);
    UpdateStateTextBlock.Text = "System Update not supported (or systemManagement capability missing)";
}

시스템 업데이트 상태 표시

계약이 있고 API가 지원되는 경우 상태 변경 알림에 등록합니다.

// Register for state change notifications
SystemUpdateManager.StateChanged += SystemUpdateManager_StateChanged;

private void SystemUpdateManager_StateChanged(object sender, object args)
{
    var action = _dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
    {
        UpdateVisualState();
    });
}

사용자 인터페이스를 초기화합니다.

// Display update information
UpdateStateTextBlock.Text = GetResourceString(SystemUpdateManager.State.ToString());
LastChecked.Text = SystemUpdateManager.LastUpdateCheckTime.ToString("G");
LastInstalled.Text = SystemUpdateManager.LastUpdateInstallTime.ToString("G");

// Attach ViewModel to ListView
UpdateItemsListView.ItemsSource = _items;

// Initialize the visual state
UpdateVisualState();
UpdateFlightRing();

BlockAutoReboot.IsOn = IsAutomaticRebootBlockOn();

UpdateVisualState 샘플 코드 함수는 다음을 수행합니다.

  1. 상태 필드를 업데이트.
  2. 마지막 업데이트 확인 시간을 업데이트.
  3. VisualStateManager 상태를 업데이트.
  4. 진행률이 있는 상태의 진행률 표시줄을 업데이트.
  5. 업데이트 항목 상태를 업데이트.

코드는 다음과 같습니다.

private void UpdateVisualState()
{
    // Update the state text
    UpdateStateTextBlock.Text = GetResourceString(SystemUpdateManager.State.ToString());

    // Update the last update check time
    LastChecked.Text = SystemUpdateManager.LastUpdateCheckTime.ToString("G");

    // Change the VisualStateManager state based on the current SystemUpdateManagerState
    var state = SystemUpdateManager.State;
    Debug.WriteLine($"State={state}");
    switch (state)
    {
        case SystemUpdateManagerState.Idle:
        case SystemUpdateManagerState.Detecting:
        case SystemUpdateManagerState.Downloading:
        case SystemUpdateManagerState.Installing:
        case SystemUpdateManagerState.RebootRequired:
            VisualStateManager.GoToState(this, SystemUpdateManager.State.ToString(), false);
            break;

        case SystemUpdateManagerState.AttentionRequired:
            AttentionRequiredTextBlock.Text = GetResourceString(SystemUpdateManager.AttentionRequiredReason.ToString());
            VisualStateManager.GoToState(this, "AttentionRequired", false);
            break;

        default:
            VisualStateManager.GoToState(this, "UnknownState", false);
            break;
    }

    // Update progress for states with progress
    switch (SystemUpdateManager.State)
    {
        case SystemUpdateManagerState.Downloading:
            Debug.WriteLine($"Downloading={SystemUpdateManager.DownloadProgress}");
            SessionDownloadProgressBar.Value = SystemUpdateManager.DownloadProgress;
            break;
        case SystemUpdateManagerState.Installing:
            Debug.WriteLine($"Installing={SystemUpdateManager.InstallProgress}");
            SessionDownloadProgressBar.Value = SystemUpdateManager.DownloadProgress;
            SessionInstallProgressBar.Value = SystemUpdateManager.InstallProgress;
            break;
    }

    // Update progress items
    switch (SystemUpdateManager.State)
    {
        case SystemUpdateManagerState.Downloading:
        case SystemUpdateManagerState.Installing:
            foreach (var updateItem in SystemUpdateManager.GetUpdateItems())
            {
                var viewModelItem = _items.Where(x => x.Id == updateItem.Id).FirstOrDefault();
                if (viewModelItem != null)
                {
                    viewModelItem.Update(updateItem);
                }
                else
                {
                    _items.Add(new UpdateItemViewModel(updateItem));
                }
            }
            break;
    }
}

시스템 업데이트 설치

디바이스 소유자가 다운로드 시작 시기를 제어하도록 자동 업데이트 프로세스 정책을 구성하거나 고객이 업데이트 프로세스를 대화형으로 시작하도록 허용하도록 선택한 경우 SystemUpdateManager.StartInstall 을 호출하면 업데이트 패키지가 있는지 확인하고 업데이트 패키지가 있는 경우 업데이트 패키지를 다운로드합니다. 비동기적으로 실행되지만 즉시 반환되는 fire-and-forget 메서드입니다.

업데이트 프로세스의 진행률은 StateChanged 이벤트 및 State 속성을 통해 추적할 수 있습니다. 다운로드가 이미 진행 중인 경우 호출은 오류 없이 즉시 반환됩니다. 상태를 진행하는 데 사용자의 주의가 필요한 경우 주의력은 AttentionRequired 로 설정되고 AttentionRequiredReason 이 설정됩니다. 복구할 수 없는 오류가 발생하면 상태가 ExtendedError로 설정되고 ExtendedError 속성이 설정됩니다.

업데이트를 시작하려면 SystemUpdateManager.StartInstall을 호출합니다. 매개 변수가 SystemUpdateStartInstallAction.UpToReboot 이면 다시 부팅이 필요할 때까지 설치가 진행됩니다. 매개 변수가 SystemUpdateStartInstallAction.AllowReboot 이면 정책이 허용하는 즉시 설치가 진행되고 다시 부팅됩니다.

private void CheckForUpdates_Click(object sender, RoutedEventArgs e)
{
    if (SystemUpdateManager.State == SystemUpdateManagerState.Idle)
    {
        SystemUpdateManager.StartInstall(SystemUpdateStartInstallAction.UpToReboot);
    }
}

시스템 업데이트 설치를 커밋하려면 재부팅이 필요한 경우가 있습니다. 이 경우 SystemUpdateManager.StateSystemUpdateManagerState.RebootRequired와 같습니다. 이 상태의 변경 내용을 완료하기 위해 정상적인 다시 부팅이 작동하지 않습니다. SystemUpdateManager.RebootToCompleteInstall을 호출하거나 시스템 업데이트 기간 동안 자동으로 예약된 다시 부팅이 발생할 때까지 기다려야 합니다(사용자 활성 시간 외).

private void RebootNow_Click(object sender, RoutedEventArgs e)
{
    if (SystemUpdateManager.State == SystemUpdateManagerState.RebootRequired)
    {
        SystemUpdateManager.RebootToCompleteInstall();
    }
}

사용자 활성 시간 관리:

private void ChangeActiveHours_Click(object sender, RoutedEventArgs e)
{
    StartTime.Time = SystemUpdateManager.UserActiveHoursStart;
    EndTime.Time = SystemUpdateManager.UserActiveHoursEnd;
    ActiveHoursErrorText.Visibility = Visibility.Collapsed;
    ActiveHoursPopup.IsOpen = true;
}

private void SaveActiveHours_Click(object sender, RoutedEventArgs e)
{
    bool succeeded = SystemUpdateManager.TrySetUserActiveHours(StartTime.Time, EndTime.Time);
    if (succeeded)
    {
        ActiveHoursPopup.IsOpen = false;
    }
    else
    {
        // Active hours not set display error message
        string format = GetResourceString("ActiveHoursErrorFormat");
        ActiveHoursErrorText.Text = String.Format(format, SystemUpdateManager.UserActiveHoursMax);
        ActiveHoursErrorText.Visibility = Visibility.Visible;
    }
}

마지막 시스템 업데이트 오류 가져오기

시스템 업데이트를 설치하는 동안 오류가 발생하면 SystemUpdateManager.LastErrorInfo 가 설정됩니다. 다음은 마지막 오류 정보를 표시하는 예제입니다.

var info = SystemUpdateManager.LastErrorInfo;
if (SystemUpdateManager.LastErrorInfo.ExtendedError == null)
{
    NoErrorText.Visibility = Visibility.Visible;
    LastErrorInfoPanel.Visibility = Visibility.Collapsed;
}
else
{
    NoErrorText.Visibility = Visibility.Collapsed;
    LastErrorInfoPanel.Visibility = Visibility.Visible;
    ErrorStateTextBlock.Text = GetResourceString(info.State.ToString());
    HResultTextBlock.Text = (info.ExtendedError == null) ? "No Error Data" : info.ExtendedError.Message;
    IsInteractiveTextBlock.Text = GetResourceString(info.IsInteractive ? "Yes" : "No");
}

시스템 업데이트 플라이트 링

플라이트 링은 비어 있거나, 카나리아, 셀프호스트 또는 사용자 정의일 수 있습니다. 값이 비어 있으면 UI에서 'None'이 선택됩니다. 그렇지 않으면 카나리아 또는 셀프 호스트가 아닌 경우 링이 사용자 정의라고 가정하고 UI 목록에 저장합니다.

private void UpdateFlightRing()
{
    var ring = Windows.System.Update.SystemUpdateManager.GetFlightRing();
    for (int i = 0; i < FlightRingCombo.Items.Count(); i++)
    {
        if (ring == FlightRingCombo.Items[i] as string)
        {
            FlightRingCombo.SelectedIndex = i;
            return;
        }
    }

    // if the current ring is non-empty and is not in the list save it to the list
    if (!String.IsNullOrEmpty(ring))
    {
        int index = FlightRingCombo.Items.Count;
        FlightRingCombo.Items.Insert(index, ring);
        FlightRingCombo.SelectedIndex = index;
        return;
    }

    FlightRingCombo.SelectedIndex = 0;
}

private void FlightRingCombo_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
    var oldRing = SystemUpdateManager.GetFlightRing();
    var newRing = e.AddedItems[0].ToString();
    Debug.WriteLine($"newRing={newRing} oldRing={oldRing}");

    if (oldRing != newRing)
    {
        if (newRing == "None")
        {
            // only set if previous ring was not null or empty
            if (!String.IsNullOrEmpty(oldRing))
            {
                Windows.System.Update.SystemUpdateManager.SetFlightRing(String.Empty);
            }
        }
        else
        {
            Windows.System.Update.SystemUpdateManager.SetFlightRing(newRing);
        }
    }
}

자동 다시 부팅 차단

시스템 업데이트가 허용되지 않음을 업데이트 서비스에 알리려면 SystemUpdateManager.UnblockAutomaticRebootAsync(id) 를 호출합니다. 여기서 id 는 숫자, 문자 및 대시로 구성된 고유한 문자열입니다. 중요한 코드 실행이 완료되면 코드는 BlockAutomaticRebootAsync에 전달된 각 ID에 대해 SystemUpdateManager.UnblockAutomaticRebootAsync를 호출해야 합니다.

if (BlockAutoReboot.IsOn)
{
    await SystemUpdateManager.BlockAutomaticRebootAsync(Guid.NewGuid().ToString());
}
else
{
    var ids = SystemUpdateManager.GetAutomaticRebootBlockIds();
    foreach(var id in ids)
    {
        bool unblocked = await SystemUpdateManager.UnblockAutomaticRebootAsync(id);
    }
}

애플리케이션은 systemManagement 기능을 선언해야 합니다. Windows 10 IoT Core만 지원됩니다.

속성

AttentionRequiredReason

사용자 주의가 필요한 이유입니다.

DownloadProgress

다운로드 진행률입니다.

ExtendedError

사용 가능한 경우 확장된 오류 정보입니다.

InstallProgress

설치 진행률입니다.

LastErrorInfo

마지막으로 실패한 시스템 업데이트에 대한 정보입니다.

LastUpdateCheckTime

업데이트에 대한 마지막 검사 시간입니다.

LastUpdateInstallTime

마지막 업데이트 설치 시간입니다.

State

SystemUpdateManager의 현재 상태입니다.

UserActiveHoursEnd

사용자 활성 시간 종료 시간 값을 가져옵니다.

UserActiveHoursMax

UserActiveHoursStartUserActiveHoursEnd 사이에 허용되는 최대 간격(시간)을 가져옵니다.

UserActiveHoursStart

사용자 활성 시간 시작 시간 값을 가져옵니다.

메서드

BlockAutomaticRebootAsync(String)

UnblockAutomaticRebootAsync가 호출되거나 시스템 정책에 의해 다시 부팅이 적용될 때까지 업데이트에 대한 자동 다시 부팅을 차단합니다.

GetAutomaticRebootBlockIds()

자동 다시 부팅 블록 요청의 ID를 가져옵니다.

GetFlightRing()

플라이트 링을 가져옵니다.

GetUpdateItems()

보류 중인 업데이트 항목 목록을 가져옵니다.

IsSupported()

이 API가 이 디바이스에서 지원되는지 여부를 나타냅니다.

RebootToCompleteInstall()

다시 부팅이 필요한 경우 디바이스를 다시 부팅하여 설치를 완료합니다.

SetFlightRing(String)

플라이트 링을 설정합니다.

StartCancelUpdates()

업데이트가 진행 중인 경우 업데이트 취소를 시작합니다.

StartInstall(SystemUpdateStartInstallAction)

보류 중인 업데이트의 검색, 다운로드 및 설치를 시작합니다.

TrySetUserActiveHours(TimeSpan, TimeSpan)

업데이트에 대한 자동 다시 부팅이 허용되지 않는 동안 사용자가 정의한 활성 시간을 설정해 보세요.

UnblockAutomaticRebootAsync(String)

차단된 경우 자동 업데이트 다시 부팅 차단을 해제합니다.

이벤트

StateChanged

상태 속성 변경 알림 이벤트입니다.

적용 대상