Portable Tool for an Ideal Windows Setup
C# activatorbloatware-removalcsharpdebloatdebloaterdisable-servicesmonitoring-systemportableprivacy-toolsregistry-tweakssystem-tuningsystem-utilitytelemetrytweakerwindows-10windows-11windows-debloatwindows-defenderwindows-optimizationwindows-tweaks
fix unhandled exception when accessing restricted registry keys (#141)
Greedeks7a5347a3fcf4
diff --git a/.Source/GTweak/Modules/Helpers/RegistryHelper.cs b/.Source/GTweak/Modules/Helpers/RegistryHelper.csindex 6671e12c..fa3b1297 100644--- a/.Source/GTweak/Modules/Helpers/RegistryHelper.cs+++ b/.Source/GTweak/Modules/Helpers/RegistryHelper.cs@@ -87,27 +87,51 @@ namespace GTweak.Modules.Helpersreturn invert ? !result : result;}- internal static bool ValueExists(string subKey, string valueName, bool invert = false)+ internal static bool CheckValue(string subKey, string valueName, string expectedValue, bool invert = false){- bool result = Registry.GetValue(subKey, valueName, null) != null;- return invert ? !result : result;+ try+ {+ string value = Registry.GetValue(subKey, valueName, null)?.ToString();+ bool result = !string.Equals(value, expectedValue, StringComparison.OrdinalIgnoreCase);+ return invert ? !result : result;+ }+ catch (Exception ex)+ {+ ErrorLogger.LogDebug(ex);+ return false;+ }}- internal static bool CheckValue(string subKey, string valueName, string expectedValue, bool invert = false)+ internal static bool ValueExists(string subKey, string valueName, bool invert = false){- string value = Registry.GetValue(subKey, valueName, null)?.ToString();- bool result = !string.Equals(value, expectedValue, StringComparison.OrdinalIgnoreCase);- return invert ? !result : result;+ try+ {+ bool result = Registry.GetValue(subKey, valueName, null) != null;+ return invert ? !result : result;+ }+ catch (Exception ex)+ {+ ErrorLogger.LogDebug(ex);+ return false;+ }}internal static bool CheckValueBytes(string subkey, string valueName, string expectedValue){- if (!(Registry.GetValue(subkey, valueName, null) is byte[] bytes))+ try{- return true;- }+ if (!(Registry.GetValue(subkey, valueName, null) is byte[] bytes))+ {+ return true;+ }- return string.Concat(bytes) != expectedValue;+ return string.Concat(bytes) != expectedValue;+ }+ catch (Exception ex)+ {+ ErrorLogger.LogDebug(ex);+ return true;+ }}internal static T GetValue<T>(string subKey, string valueName, T defaultValue)