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.7 kB

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