Skip to content

Commit

Permalink
4.9.1
Browse files Browse the repository at this point in the history
Fix AutoStartup
  • Loading branch information
HMBSbige committed Dec 17, 2018
1 parent 7c39e1a commit 8f35447
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 15 deletions.
13 changes: 6 additions & 7 deletions shadowsocks-csharp/Controller/AutoStartup.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
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)
{
RegistryKey runKey = null;
try
{
string path = Util.Utils.GetExecutablePath();
runKey = Registry.LocalMachine.OpenSubKey(RegistryRunPath, true);
runKey = Util.Utils.OpenRegKey(RegistryRunPath, true);
if (enabled)
{
runKey.SetValue(Key, path);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion shadowsocks-csharp/Controller/UpdateChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
20 changes: 13 additions & 7 deletions shadowsocks-csharp/Util/Util.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
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;
using System.IO;
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
{
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit 8f35447

Please sign in to comment.