using Microsoft.Win32;
using System.Diagnostics;
public class AutoStart
{
public const string KeyPath = @"SOFTWARE\Microsoft\Windows\CurrentVersion\Run";
public static void Set(bool value)
{
using (var key = Registry.CurrentUser.OpenSubKey(KeyPath, true))
{
var process = Process.GetCurrentProcess();
if (value)
{
key.SetValue(process.ProcessName, process.MainModule.FileName);
}
else
{
key.DeleteValue(process.ProcessName, false);
}
}
}
public static bool IsEnabled()
{
using (var key = Registry.CurrentUser.OpenSubKey(KeyPath))
{
var process = Process.GetCurrentProcess();
return key.GetValue(process.ProcessName) != null;
}
}
}