private async void WindowX_Loaded(object sender, RoutedEventArgs e) { Console.SetOut(consoleRedirect); if (UpdateRequest != null) { //获得当前登录的Windows用户标示 WindowsIdentity identity = WindowsIdentity.GetCurrent(); WindowsPrincipal principal = new WindowsPrincipal(identity); //判断当前登录用户是否为管理员 if (principal.IsInRole(WindowsBuiltInRole.Administrator)) { UniversalUpdater updater = new UniversalUpdater(UpdateRequest); try { await updater.StartAsync(UpdateProgressSafely); } catch (Exception ex) { viewModel.UpdateMessage = ex.Message + ",程序即将退出!"; } } else { viewModel.UpdateMessage = "当前程序无管理员权限,程序即将退出!"; } } else { viewModel.UpdateMessage = "缺少升级所需的参数UpdateRequest.json,程序即将退出!"; } await Task.Delay(5000); OnClose(); }
static void RunAsConsole(string[] args, UpdateRequest request) { UniversalUpdater updater = new UniversalUpdater(request); try { updater.Start(UpdateProgress); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }