using Microsoft.Win32; using WindowsGotify.Services; namespace WindowsGotify.Utils; public static class StartupManager { private const string RunKey = @"Software\Microsoft\Windows\CurrentVersion\Run"; private const string AppName = "WindowsGotify"; public static void EnableCurrentUserStartup(Logger logger) { try { using var key = Registry.CurrentUser.OpenSubKey(RunKey, writable: true) ?? Registry.CurrentUser.CreateSubKey(RunKey, writable: true); var exe = Environment.ProcessPath; if (string.IsNullOrWhiteSpace(exe)) return; key.SetValue(AppName, $"\"{exe}\"", RegistryValueKind.String); logger.Info("Current-user startup enabled."); } catch (Exception ex) { logger.Error("Failed to enable startup.", ex); } } public static void DisableCurrentUserStartup(Logger logger) { try { using var key = Registry.CurrentUser.OpenSubKey(RunKey, writable: true); key?.DeleteValue(AppName, throwOnMissingValue: false); logger.Info("Current-user startup disabled."); } catch (Exception ex) { logger.Error("Failed to disable startup.", ex); } } }