using System; using Microsoft.Win32; namespace Terius.Automate.Agent.Services; public sealed class StartupManager { private const string RunKey = @"Software\Microsoft\Windows\CurrentVersion\Run"; private const string ValueName = "TERIUSAutomateAgent"; public void Apply(bool enabled) { using var key = Registry.CurrentUser.OpenSubKey(RunKey, writable: true) ?? Registry.CurrentUser.CreateSubKey(RunKey, writable: true); if (enabled) { var executable = Environment.ProcessPath ?? throw new InvalidOperationException("No se pudo determinar la ruta del agente."); key.SetValue(ValueName, $"\"{executable}\" --background"); } else { key.DeleteValue(ValueName, throwOnMissingValue: false); } } }