public static bool windowsAutomaticUpdatesActivated() { WUApiLib.AutomaticUpdatesClass auc = new WUApiLib.AutomaticUpdatesClass(); return !(auc.Settings.NotificationLevel == WUApiLib.AutomaticUpdatesNotificationLevel.aunlDisabled); }
public static bool windowsUpdateActivated() { WUApiLib.AutomaticUpdatesClass auc = new WUApiLib.AutomaticUpdatesClass(); return auc.ServiceEnabled; }
private async void CheckWindowsUpdateSettings() { StopRegistryKeyWatchers(); _checkRunning = true; _checkPending = false; AppendLogText("Checking Windows Update settings"); var runWindowsUpdate = false; var key1 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate", true); if (key1?.GetValue("DisableDualScan") != null) { AppendLogText("Deleting 'DisableDualScan' registry key"); key1.DeleteValue("DisableDualScan"); runWindowsUpdate = true; } var key2 = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Policies\Microsoft\Windows\WindowsUpdate\AU", true); if (key2?.GetValue("NoAutoUpdate") != null) { AppendLogText("Deleting 'NoAutoUpdate' registry key"); key2.DeleteValue("NoAutoUpdate"); runWindowsUpdate = true; } if (runWindowsUpdate) { AppendLogText("Executing Windows Update check"); var windowsUpdate = new WUApiLib.AutomaticUpdatesClass(); if (!windowsUpdate.ServiceEnabled) { windowsUpdate.EnableService(); await Task.Delay(1000); } // 0x8024A000 - No AU available. Error codes here: https://support.microsoft.com/en-us/help/938205/windows-update-error-code-list try { windowsUpdate.DetectNow(); } catch (Exception e) { AppendLogText($"Error executing Windows Update check: {e}"); } } _checkRunning = false; StartRegistryKeyWatchers(); }