using Microsoft.Win32; using System.Configuration; namespace Agent.Services { class StartupService { private readonly RegistryKey _regKey = Registry.CurrentUser.OpenSubKey(@ConfigurationManager.AppSettings["RegPath"], true); private readonly string _programName = @ConfigurationManager.AppSettings["ProgramName"]; /// /// 시작프로그램 등록 여부 /// /// public bool IsRegist() { return null != _regKey.GetValue(_programName); } /// /// 시작프로그램 등록 /// public void Enabled() { if (!IsRegist()) { _regKey.SetValue(_programName, System.Windows.Forms.Application.ExecutablePath); } } /// /// 시작프로그램 삭제 /// public void Disabled() { if (IsRegist()) { _regKey.DeleteValue(_programName); } } public bool GetStatusWithToggle(bool isRegist) { if (isRegist) { Enabled(); return IsRegist(); } Disabled(); return IsRegist(); } } }