12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- 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"];
- /// <summary>
- /// 시작프로그램 등록 여부
- /// </summary>
- /// <returns></returns>
- public bool IsRegist()
- {
- return null != _regKey.GetValue(_programName);
- }
- /// <summary>
- /// 시작프로그램 등록
- /// </summary>
- public void Enabled()
- {
- if (!IsRegist())
- {
- _regKey.SetValue(_programName, System.Windows.Forms.Application.ExecutablePath);
- }
- }
- /// <summary>
- /// 시작프로그램 삭제
- /// </summary>
- public void Disabled()
- {
- if (IsRegist())
- {
- _regKey.DeleteValue(_programName);
- }
- }
- public bool GetStatusWithToggle(bool isRegist)
- {
- if (isRegist)
- {
- Enabled();
- return IsRegist();
- }
- Disabled();
- return IsRegist();
- }
- }
- }
|