diff --git a/LightBulb.PlatformInterop/RegistrySwitch.cs b/LightBulb.PlatformInterop/RegistrySwitch.cs index 0914f6e..16f8075 100644 --- a/LightBulb.PlatformInterop/RegistrySwitch.cs +++ b/LightBulb.PlatformInterop/RegistrySwitch.cs @@ -47,13 +47,17 @@ public bool IsSet { // Run reg.exe with elevation if (value) + { Reg.SetValue( hive.GetShortMoniker() + '\\' + keyName, entryName, enabledValue ); + } else + { Reg.DeleteValue(hive.GetShortMoniker() + '\\' + keyName, entryName); + } } } } diff --git a/LightBulb/Services/SettingsService.cs b/LightBulb/Services/SettingsService.cs index 28ecc9a..8b62564 100644 --- a/LightBulb/Services/SettingsService.cs +++ b/LightBulb/Services/SettingsService.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.ComponentModel; using System.IO; using System.Text.Json.Serialization; using Cogwheel; @@ -278,8 +279,18 @@ public override void Save() base.Save(); // Update values in the registry - _extendedGammaRangeSwitch.IsSet = IsExtendedGammaRangeUnlocked; - _autoStartSwitch.IsSet = IsAutoStartEnabled; + try + { + _extendedGammaRangeSwitch.IsSet = IsExtendedGammaRangeUnlocked; + _autoStartSwitch.IsSet = IsAutoStartEnabled; + } + catch (Win32Exception) + { + // This can happen if the user doesn't have the necessary permissions to update + // the corresponding registry keys, and privilege elevation has failed. + // Throwing an exception here is very messy, so we'll just ignore it. + // https://github.com/Tyrrrz/LightBulb/issues/335 + } // Trigger UI updates OnPropertyChanged(string.Empty);