//设置自动登录并移动到下一个用户 async Task SetAutoLogon() { var msg = "设置自动登录中..."; loadingTextControl.Text = msg; LogHelper.WriteLog(msg); await Task.Factory.StartNew(() => { try { MoveNext(); var currentUser = Users[CurrentIndex]; RegisterTool.WriteDefaultLogin(currentUser, object.Equals(ConfigurationManager.AppSettings["IsEnableDomain"], "true")); System.Diagnostics.Process.Start("shutdown", @"/r /t 0"); } catch (Exception ex) { msg += "遇到错误"; LogHelper.WriteLog(msg, ex); } }); }
async Task <bool> SetRestart() { var msg = "设置检查当前用户中..."; var currentUser = Users[CurrentIndex]; loadingTextControl.Text = msg; LogHelper.WriteLog(msg); return(await Task <bool> .Factory.StartNew(() => { try { //如果当前用户是excel表格里面的第一个用户 if (Environment.UserName != currentUser.UserName) { return this.Dispatcher.Invoke(() => { var result = MessageBox.Show("当前登录用户和要执行用户不是同一用户,是否重启?", "", MessageBoxButton.YesNo); if (result == MessageBoxResult.Yes) { RegisterTool.WriteDefaultLogin(currentUser, object.Equals(ConfigurationManager.AppSettings["IsEnableDomain"], "true")); System.Diagnostics.Process.Start("shutdown", @"/r /t 0"); return true; } else { return false; } }); } return true; } catch (Exception ex) { msg += "遇到错误"; LogHelper.WriteLog(msg, ex); return false; } })); }