Make registry opening more generic
Signed-off-by: Syrone Wong <wong.syrone@gmail.com>
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user