private void BtInstall_Click(object sender, RoutedEventArgs e) { var ww = new WarningDialog { ShowActivated = true, Owner = Application.Current.MainWindow, }; ww.ShowDialog(); if (ww.Abort) { return; } ScheduleGrid.IsEnabled = false; BtInstall.IsEnabled = false; DetailsExpander.IsExpanded = false; DetailsExpander.IsEnabled = false; SetStatus(ScheduleStatus.Orange); SqlCe.SetAutoEnforceFlag(true); SqlCe.DeleteServiceSchedule(); SqlCe.UpdateSupData("STD", string.Empty); CcmUtils.InstallAllAppsAndUpdates(); if (_pipeClient == null) { _pipeClient = new PipeClient(); } _pipeClient.Send("SetRed", "01DB94E3-90F1-43F4-8DDA-8AEAF6C08A8E"); Globals.Log.Information("Sent icon switch command to tray."); }
private void BtInstall_Click(object sender, RoutedEventArgs e) { BtInstall.IsEnabled = false; BtSchedule.IsEnabled = false; TpPicker.IsEnabled = false; SqlCe.UpdateSupData("STD", string.Empty); if (_isReschedule) { SqlCe.SetEnforcedFlag(_scheduleId); } SqlCe.SetUpdatesInstallStatusFlag(true); CcmUtils.ExecuteInstallUpdates(true); SetStatus(ScheduleStatus.Green); StatusText.Text = "Installation has been initiated."; }
private void EnforcementTimer_Elapsed(object sender, System.Timers.ElapsedEventArgs e) { _enforcementTimer.Stop(); _enforcementTimer.Interval = AutoInterval(); _enforcementTimer.Start(); SaveAssignmentsToDB(); if (SqlCe.GetAutoEnforceFlag()) { Globals.Log.Information("Checking Service cycle status."); var reqApps = CcmUtils.RequiredApps.Where(x => !x.InstallState.Equals("Installed") && x.EvaluationState == 3 && !x.IsIpuApplication).ToList(); var pendingUpdates = CcmUtils.Updates.ToList(); if (reqApps.Count() == 0 && pendingUpdates.Count() == 0 && !(CcmUtils.IsUpdatesEnforcing() || CcmUtils.IsAppsEnforcing()) && !RebootChecker.RebootRequired(new RestartChecks() { PendingFileOperations = true }).Any) { Globals.Log.Information("Service cycle - Resetting Auto Enforce Flag, nothing left to enforce and no reboot pending."); SqlCe.SetAutoEnforceFlag(false); _pipeClient.Send("SetBlue", "01DB94E3-90F1-43F4-8DDA-8AEAF6C08A8E"); _iEnforcementInterval = 5; if (UnsafeNativeMethods.IsUserLoggedOn()) { UnsafeNativeMethods.Run(_userApp, $"/ToastServiceEndNotification", false); } if (_settings.LegalNotice.UseLegalNotice) { Reg.RemoveLegalNotice(); } return; } else if (CcmUtils.IsRebootPending().HardRebootPending&& !(CcmUtils.IsUpdatesEnforcing() || CcmUtils.IsAppsEnforcing())) { Globals.Log.Information("Service cycle - Pending hard reboot detected - restarting computer."); if (UnsafeNativeMethods.IsUserLoggedOn()) { UnsafeNativeMethods.Run(_userApp, $"/ToastServiceRestartNotification", false); RestartComputer(); } else { RestartComputer(true); } return; } else if (!(CcmUtils.IsUpdatesEnforcing() || CcmUtils.IsAppsEnforcing()) && (reqApps.Count() != 0 || pendingUpdates.Count() != 0)) { Globals.Log.Information("Service cycle - Cycle running but required installations not enforcing - pushing enforcement."); CcmUtils.InstallAllAppsAndUpdates(); return; } else if (reqApps.Count() == 0 && pendingUpdates.Count() == 0 && !(CcmUtils.IsUpdatesEnforcing() || CcmUtils.IsAppsEnforcing()) && RebootChecker.RebootRequired(new RestartChecks() { PendingFileOperations = true }).Any) { Globals.Log.Information("Service cycle - nothing left to enforce but a pending reboot (Any) was detected - restarting computer."); if (UnsafeNativeMethods.IsUserLoggedOn()) { UnsafeNativeMethods.Run(_userApp, $"/ToastServiceRestartNotification", false); RestartComputer(); } else { RestartComputer(true); } return; } Globals.Log.Information("Service cycle not yet finished."); return; } if (CcmUtils.IsUpdatesEnforcing()) { return; } var rs = SqlCe.GetRestartSchedule(); if (rs != null) { if (rs.RestartTime <= DateTime.Now) { SqlCe.DeleteRestartSchedule(); if (UnsafeNativeMethods.IsUserLoggedOn()) { UnsafeNativeMethods.Run(_userApp, $"/ShowRestartWindow", false); Globals.Log.Information($"Launched Restart Window."); } else { RestartComputer(true); } return; } } RestartRequired(); if (CcmUtils.IsRebootPending().HardRebootPending) { Globals.Log.Warning($"Detected pending hard reboot - postponing further enforcement(s)"); return; } try { var serviceSchedule = CommonUtils.GetNextServiceCycleAsDateTime(); if (serviceSchedule != null) { if (serviceSchedule <= DateTime.Now) { SqlCe.SetAutoEnforceFlag(true); _pipeClient.Send("SetRed", "01DB94E3-90F1-43F4-8DDA-8AEAF6C08A8E"); CcmUtils.InstallAllAppsAndUpdates(); _iEnforcementInterval = 1; _enforcementTimer.Stop(); _enforcementTimer.Interval = AutoInterval(); _enforcementTimer.Start(); if (_settings.LegalNotice.UseLegalNotice) { Reg.SetLegalNotice(_settings.LegalNotice); } SqlCe.DeleteServiceSchedule(); SqlCe.UpdateSupData("STD", string.Empty); if (UnsafeNativeMethods.IsUserLoggedOn()) { UnsafeNativeMethods.Run(_userApp, $"/ToastServiceInitNotification", false); } Globals.Log.Information($"Found and triggered a Service Schedule (Install All)"); return; } } } catch (Exception ex) { Globals.Log.Error(ex.Message); } try { var sch = SqlCe.GetDueSchedules(); if (sch.Count() > 0) { Globals.Log.Information($"Found {sch.Count()} objects due for enforcement."); sch.ForEach(x => _objectsToEnforce.Add(x)); } else { Globals.Log.Information($"No scheduled enforcements found at this time"); } } catch (Exception ex) { Globals.Log.Error(ex.Message); } try { if (CcmUtils.IsApplicationEvaluationRequired()) { CcmUtils.EvaluateAllPolicies(); } } catch (Exception ex) { Globals.Log.Error(ex.Message); } }
private void CheckForSups() { if (_supCheckBlocked || SqlCe.GetAutoEnforceFlag()) { return; } try { var sups = CcmUtils.Updates; if (sups.Count() == 0) { _lastFoundSups = null; Globals.Log.Information("No updates available at this time"); return; } _lastFoundSups = _lastFoundSups ?? DateTime.Now; if (_lastFoundSups > DateTime.Now.AddMinutes(-5)) { return; } var jsonSups = JsonConvert.SerializeObject(sups); SqlCe.UpdateSupData("STD", jsonSups); Globals.Log.Information($"Found {sups.Count()} updates available for scheduling"); var nextSchedule = SqlCe.GetNextSupSchedule(); var supdeadline = sups.OrderBy(y => y.Deadline).First().Deadline; var nextServiceCycle = SqlCe.GetServiceSchedule(); if (nextSchedule.Id != 0) { Globals.Log.Information($"Next update enforcement time '{nextSchedule.EnforcementTime}' deadline for available updates = '{supdeadline}', 'toasting' user - reschedule necessary"); if (nextSchedule.EnforcementTime <= supdeadline) { Globals.Log.Information($"Next update enforcement time '{nextSchedule.EnforcementTime}' deadline for available updates = '{supdeadline}', skipping 'toast'"); return; } else { SqlCe.SetEnforcedFlag(nextSchedule.Id); } } var dtNextServiceCycle = CommonUtils.GetNextServiceCycleAsDateTime(); if (dtNextServiceCycle != null) { if (dtNextServiceCycle <= supdeadline) { Globals.Log.Information($"Detected an upcoming service cycle, a Toast notification was suppressed."); return; } } if (UnsafeNativeMethods.IsUserLoggedOn() && !RegistryMethods.GetIpuIsRunning()) { if (!UnsafeNativeMethods.IsSessionLocked()) { UnsafeNativeMethods.Run(_userApp, $"/ToastSup", false); } else { Globals.Log.Information($"Detected a locked or non existing user session, a Toast notification was suppressed."); } } } catch (Exception ex) { Globals.Log.Error(ex.Message); } }
private void EnforcePump() { Task.Run(() => { while (true) { try { var scheduledobject = _objectsToEnforce.Take(); _allowFastReboot = scheduledobject.IsAutoSchedule; SqlCe.SetEnforcedFlag(scheduledobject.Id); if (scheduledobject.EnforcementType.Equals("APP")) { var cmapp = CcmUtils.GetSpecificApp(scheduledobject); if (cmapp == null) { Globals.Log.Warning($"A scheduled enforcement '{scheduledobject.ObjectId}/{scheduledobject.Revision}' could not be performed. Deployment has been removed or changed?"); continue; } if (scheduledobject.Action.Equals("I")) { if (cmapp.IsIpuApplication && _settings.IpuApplication.ShowDialog1 && UnsafeNativeMethods.IsUserLoggedOn()) { if (UnsafeNativeMethods.Run(_userApp, "/ShowIpuDialog1", true) == 0) { //RegistryMethods.SetIpuIsRunning(); //CcmUtils.InstallApplication(cmapp); InstallIpuApplication(cmapp); Globals.Log.Information($"User pressed 'Install' feature updated '{cmapp.Name}'"); } else { SqlCe.DeleteAppSchedule(cmapp.Id, cmapp.Revision); Globals.Log.Warning($"User aborted a scheduled Windows feature upgrade '{cmapp.Name}'"); } } else if (cmapp.IsIpuApplication) { //RegistryMethods.SetIpuIsRunning(); InstallIpuApplication(cmapp); //CcmUtils.InstallApplication(cmapp); } else { CcmUtils.InstallApplication(cmapp); } } else if (scheduledobject.Action.Equals("R")) { CcmUtils.RepairApplication(cmapp); } else { CcmUtils.UninstallApplication(cmapp); } } else if (scheduledobject.EnforcementType.Equals("SUP")) { Globals.Log.Information("Installing updates, disabling component servicing reboot detection until rebooted."); _rebootServicingCheck = false; Set_SupCheckBlocked(); SqlCe.UpdateSupData("STD", string.Empty); CcmUtils.ExecuteInstallUpdates(true); } } catch (Exception ex) { Globals.Log.Error(ex.Message); } } }); }