diff --git a/shadowsocks-csharp/Controller/System/AutoStartup.cs b/shadowsocks-csharp/Controller/System/AutoStartup.cs index 688ff362..c9f3d775 100644 --- a/shadowsocks-csharp/Controller/System/AutoStartup.cs +++ b/shadowsocks-csharp/Controller/System/AutoStartup.cs @@ -15,7 +15,7 @@ namespace Shadowsocks.Controller try { string path = Application.ExecutablePath; - runKey = Utils.OpenUserRegKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true); + runKey = Utils.OpenRegKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true); if ( runKey == null ) { Logging.Error( @"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run" ); return false; @@ -54,7 +54,7 @@ namespace Shadowsocks.Controller try { string path = Application.ExecutablePath; - runKey = Utils.OpenUserRegKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true); + runKey = Utils.OpenRegKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true); if (runKey == null) { Logging.Error(@"Cannot find HKCU\Software\Microsoft\Windows\CurrentVersion\Run"); return false; diff --git a/shadowsocks-csharp/Util/Util.cs b/shadowsocks-csharp/Util/Util.cs index e6017432..60a748e2 100755 --- a/shadowsocks-csharp/Util/Util.cs +++ b/shadowsocks-csharp/Util/Util.cs @@ -211,7 +211,7 @@ namespace Shadowsocks.Util return new BandwidthScaleInfo(f, unit, scale); } - public static RegistryKey OpenUserRegKey( string name, bool writable ) + public static RegistryKey OpenRegKey( string name, bool writable, RegistryHive hive = RegistryHive.CurrentUser ) { // we are building x86 binary for both x86 and x64, which will // cause problem when opening registry key @@ -219,7 +219,7 @@ namespace Shadowsocks.Util if (name.IsNullOrEmpty()) throw new ArgumentException(nameof(name)); try { - RegistryKey userKey = RegistryKey.OpenBaseKey(RegistryHive.CurrentUser, + RegistryKey userKey = RegistryKey.OpenBaseKey(hive, Environment.Is64BitOperatingSystem ? RegistryView.Registry64 : RegistryView.Registry32) .OpenSubKey(name, writable); return userKey; @@ -236,7 +236,7 @@ namespace Shadowsocks.Util } catch (ArgumentException ae) { - MessageBox.Show("OpenUserRegKey: " + ae.ToString()); + MessageBox.Show("OpenRegKey: " + ae.ToString()); return null; } }