You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

AutoStartup.cs 1.0 kB

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Windows.Forms;
  3. using Microsoft.Win32;
  4. namespace Shadowsocks.Controller {
  5. class AutoStartup {
  6. public static bool Set(bool enabled) {
  7. try {
  8. string path = Application.ExecutablePath;
  9. RegistryKey runKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run", true);
  10. if (enabled) {
  11. runKey.SetValue("Shadowsocks", path);
  12. } else {
  13. runKey.DeleteValue("Shadowsocks");
  14. }
  15. runKey.Close();
  16. return true;
  17. } catch (Exception) {
  18. return false;
  19. }
  20. }
  21. public static bool Check() {
  22. try {
  23. string path = Application.ExecutablePath;
  24. RegistryKey runKey = Microsoft.Win32.Registry.CurrentUser.OpenSubKey(@"Software\Microsoft\Windows\CurrentVersion\Run");
  25. string[] runList = runKey.GetValueNames();
  26. runKey.Close();
  27. foreach (string item in runList) {
  28. if (item.Equals("Shadowsocks"))
  29. return true;
  30. }
  31. return false;
  32. } catch (Exception) {
  33. return false;
  34. }
  35. }
  36. }
  37. }