StartupService.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using Microsoft.Win32;
  2. using System.Configuration;
  3. namespace Agent.Services
  4. {
  5. class StartupService
  6. {
  7. private readonly RegistryKey _regKey = Registry.CurrentUser.OpenSubKey(@ConfigurationManager.AppSettings["RegPath"], true);
  8. private readonly string _programName = @ConfigurationManager.AppSettings["ProgramName"];
  9. /// <summary>
  10. /// 시작프로그램 등록 여부
  11. /// </summary>
  12. /// <returns></returns>
  13. public bool IsRegist()
  14. {
  15. return null != _regKey.GetValue(_programName);
  16. }
  17. /// <summary>
  18. /// 시작프로그램 등록
  19. /// </summary>
  20. public void Enabled()
  21. {
  22. if (!IsRegist())
  23. {
  24. _regKey.SetValue(_programName, System.Windows.Forms.Application.ExecutablePath);
  25. }
  26. }
  27. /// <summary>
  28. /// 시작프로그램 삭제
  29. /// </summary>
  30. public void Disabled()
  31. {
  32. if (IsRegist())
  33. {
  34. _regKey.DeleteValue(_programName);
  35. }
  36. }
  37. public bool GetStatusWithToggle(bool isRegist)
  38. {
  39. if (isRegist)
  40. {
  41. Enabled();
  42. return IsRegist();
  43. }
  44. Disabled();
  45. return IsRegist();
  46. }
  47. }
  48. }