diff --git a/shadowsocks-csharp/Controller/AutoStartup.cs b/shadowsocks-csharp/Controller/AutoStartup.cs index b2c64ea31a..0849fb4a56 100644 --- a/shadowsocks-csharp/Controller/AutoStartup.cs +++ b/shadowsocks-csharp/Controller/AutoStartup.cs @@ -1,13 +1,13 @@ -using System; +using Microsoft.Win32; +using System; using System.Windows.Forms; -using Microsoft.Win32; namespace Shadowsocks.Controller { class AutoStartup { static string Key = "ShadowsocksR_" + Application.StartupPath.GetHashCode(); - static string RegistryRunPath = (IntPtr.Size == 4 ? @"Software\Microsoft\Windows\CurrentVersion\Run" : @"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Run"); + static string RegistryRunPath = @"Software\Microsoft\Windows\CurrentVersion\Run"; public static bool Set(bool enabled) { @@ -15,7 +15,7 @@ public static bool Set(bool enabled) try { string path = Util.Utils.GetExecutablePath(); - runKey = Registry.LocalMachine.OpenSubKey(RegistryRunPath, true); + runKey = Util.Utils.OpenRegKey(RegistryRunPath, true); if (enabled) { runKey.SetValue(Key, path); @@ -55,7 +55,7 @@ public static bool Switch() try { string path = Util.Utils.GetExecutablePath(); - runKey = Registry.LocalMachine.OpenSubKey(RegistryRunPath, true); + runKey = Util.Utils.OpenRegKey(RegistryRunPath, true); if (enabled) { runKey.SetValue(Key, path); @@ -93,8 +93,7 @@ public static bool Check() RegistryKey runKey = null; try { - string path = Util.Utils.GetExecutablePath(); - runKey = Registry.LocalMachine.OpenSubKey(RegistryRunPath, false); + runKey = Util.Utils.OpenRegKey(RegistryRunPath, false); string[] runList = runKey.GetValueNames(); runKey.Close(); foreach (string item in runList) diff --git a/shadowsocks-csharp/Controller/UpdateChecker.cs b/shadowsocks-csharp/Controller/UpdateChecker.cs index 4fe189b523..9dadc0d612 100755 --- a/shadowsocks-csharp/Controller/UpdateChecker.cs +++ b/shadowsocks-csharp/Controller/UpdateChecker.cs @@ -22,7 +22,7 @@ public class UpdateChecker public const string Name = @"ShadowsocksR"; public const string Copyright = @"Copyright © BreakWa11 2017. Fork from Shadowsocks by clowwindy"; - public const string Version = @"4.9.0"; + public const string Version = @"4.9.1"; #if !_DOTNET_4_0 public const string NetVer = @"2.0"; #elif !_CONSOLE diff --git a/shadowsocks-csharp/Util/Util.cs b/shadowsocks-csharp/Util/Util.cs index 22c3240661..d5bcd232f5 100755 --- a/shadowsocks-csharp/Util/Util.cs +++ b/shadowsocks-csharp/Util/Util.cs @@ -1,4 +1,8 @@ -using System; +using Microsoft.Win32; +using OpenDNS; +using Shadowsocks.Controller; +using Shadowsocks.Model; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; @@ -6,15 +10,9 @@ using System.IO.Compression; using System.Net; using System.Net.Sockets; -using System.Reflection; using System.Runtime.InteropServices; using System.Security.Cryptography; -using System.Text; using System.Windows.Forms; -using OpenDNS; -using Shadowsocks.Controller; -using Shadowsocks.Encryption; -using Shadowsocks.Model; namespace Shadowsocks.Util { @@ -456,6 +454,14 @@ public static string GetExecutablePath() return System.Reflection.Assembly.GetExecutingAssembly().Location; } + public static RegistryKey OpenRegKey(string name, bool writable, RegistryHive hive = RegistryHive.CurrentUser) + { + var userKey = RegistryKey.OpenBaseKey(hive, + Environment.Is64BitProcess ? RegistryView.Registry64 : RegistryView.Registry32) + .OpenSubKey(name, writable); + return userKey; + } + public static int RunAsAdmin(string Arguments) { Process process = null;