diff --git a/GreenshotPlugin/Core/EmailConfigHelper.cs b/GreenshotPlugin/Core/EmailConfigHelper.cs index 354f02c33..9eb8a7bfe 100644 --- a/GreenshotPlugin/Core/EmailConfigHelper.cs +++ b/GreenshotPlugin/Core/EmailConfigHelper.cs @@ -28,16 +28,15 @@ namespace GreenshotPlugin.Core { /// public static class EmailConfigHelper { - public static string GetMapiClient() => Registry.LocalMachine.ReadKey64Or32(@"Clients\Mail"); + public static string GetMapiClient() => RegistryHive.LocalMachine.ReadKey64Or32(@"Clients\Mail"); public static bool HasMapi() { - var value = Registry.LocalMachine.ReadKey64Or32(@"Microsoft\Windows Messaging Subsystem", "MAPI", "0"); + var value = RegistryHive.LocalMachine.ReadKey64Or32(@"Microsoft\Windows Messaging Subsystem", "MAPI", "0"); return "1".Equals(value); - } - public static string GetOutlookExePath() => Registry.LocalMachine.ReadKey64Or32(@"Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE"); + public static string GetOutlookExePath() => RegistryHive.LocalMachine.ReadKey64Or32(@"Microsoft\Windows\CurrentVersion\App Paths\OUTLOOK.EXE"); /// /// Check if Outlook is installed diff --git a/GreenshotPlugin/Core/RegistryKeyExtensions.cs b/GreenshotPlugin/Core/RegistryKeyExtensions.cs index 73fd66a47..bfdb63e10 100644 --- a/GreenshotPlugin/Core/RegistryKeyExtensions.cs +++ b/GreenshotPlugin/Core/RegistryKeyExtensions.cs @@ -32,36 +32,57 @@ namespace GreenshotPlugin.Core /// /// Retrieve a registry value /// - /// RegistryKey like Registry.LocalMachine + /// RegistryHive like RegistryHive.LocalMachine /// string with the name of the key /// string with the name of the value below the key, null will retrieve the default /// string with the default value to return /// string with the value - public static string ReadKey64Or32(this RegistryKey registryKey, string keyName, string value = null, string defaultValue = null) + public static string ReadKey64Or32(this RegistryHive registryHive, string keyName, string value = null, string defaultValue = null) { string result = null; value ??= string.Empty; - if (Environment.Is64BitOperatingSystem) + + using var registryKey32 = RegistryKey.OpenBaseKey(registryHive, RegistryView.Registry32); + // Logic for 32-bit Windows is just reading the key + if (!Environment.Is64BitOperatingSystem) { - using var key = registryKey.OpenSubKey($@"SOFTWARE\{keyName}", false); - + using var key = registryKey32.OpenSubKey($@"SOFTWARE\{keyName}", false); + if (key != null) { - result = (string)key.GetValue(value, defaultValue); + result = (string)key.GetValue(value); + } + if (string.IsNullOrEmpty(result)) + { + result = defaultValue; + } + return result; + } + using var registryKey64 = RegistryKey.OpenBaseKey(registryHive, RegistryView.Registry64); + // Logic for 64 bit Windows, is trying the key which is 64 bit + using (var key = registryKey64.OpenSubKey($@"SOFTWARE\{keyName}", false)) + { + if (key != null) + { + result = (string)key.GetValue(value); + } + if (!string.IsNullOrEmpty(result)) return result; + } + + // if there is no value use the wow6432node key which is 32 bit + using (var key = registryKey32.OpenSubKey($@"SOFTWARE\{keyName}", false)) + { + if (key != null) + { + result = (string)key.GetValue(value); } } if (string.IsNullOrEmpty(result)) { - using var key = registryKey.OpenSubKey($@"SOFTWARE\wow6432node\{keyName}", false); - - if (key != null) - { - result = (string)key.GetValue(value, defaultValue); - } + result = defaultValue; } - return result; } } -} +} \ No newline at end of file