40 lines
1015 B
C#
40 lines
1015 B
C#
using System;
|
|
using System.Windows.Forms;
|
|
using Microsoft.Win32;
|
|
|
|
namespace Shadowsocks.Controller {
|
|
class AutoStartup {
|
|
public static bool Set(bool enabled) {
|
|
try {
|
|
string path = Application.ExecutablePath;
|
|
RegistryKey runKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
|
|
if (enabled) {
|
|
runKey.SetValue("Shadowsocks", path);
|
|
} else {
|
|
runKey.DeleteValue("Shadowsocks");
|
|
}
|
|
runKey.Close();
|
|
return true;
|
|
} catch (Exception) {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
public static bool Check() {
|
|
try {
|
|
string path = Application.ExecutablePath;
|
|
RegistryKey runKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
|
|
string[] runList = runKey.GetValueNames();
|
|
runKey.Close();
|
|
foreach (string item in runList) {
|
|
if (item.Equals("Shadowsocks"))
|
|
return true;
|
|
}
|
|
return false;
|
|
} catch (Exception) {
|
|
return false;
|
|
}
|
|
}
|
|
}
|
|
}
|