以编程方式设置系统时间

Set System Time programmatically

是否可以从 uwp 应用程序设置系统日期和时间? 我只是在尝试一种简单的方法。但这会引发错误。

void winrt::Calender::implementation::MainPage::datePicker_DateChanged(winrt::Windows::UI::Xaml::Controls::CalendarDatePicker const& sender, winrt::Windows::UI::Xaml::Controls::CalendarDatePickerDateChangedEventArgs const& args)
{
    Windows::System::DateTimeSettings::SetSystemDateTime(args.NewDate().GetDateTime());
}

WinRT originate error - 0x80004001 : 'Not implemented'.

此 API 仅针对物联网设备实施,需要 systemManagement 功能。

无论如何,设置系统时间都需要 Desktop 的管理员权限,因此 UWP 通常无法做到这一点。

If you want to know why system time is protected in this way, see Microsoft Docs