Browse Source

Make registry opening more generic

Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
tags/3.3.4
Syrone Wong 8 years ago
parent
commit
4b99a5c210
2 changed files with 5 additions and 5 deletions
  1. +2
    -2
      shadowsocks-csharp/Controller/System/AutoStartup.cs
  2. +3
    -3
      shadowsocks-csharp/Util/Util.cs

+ 2
- 2
shadowsocks-csharp/Controller/System/AutoStartup.cs View File

@@ -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;


+ 3
- 3
shadowsocks-csharp/Util/Util.cs View File

@@ -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;
}
}


Loading…
Cancel
Save