The simplest method (in my opinion) relies on the Windows registry.
using Microsoft.Win32;
namespace WindowsStartupTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
checkBoxRegistry.Checked = (registryKey().GetValue(Application.ProductName) != null);
}
private RegistryKey registryKey()
{
return Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Run")!;
}
private void checkBoxRegistry_Click(object sender, EventArgs e)
{
if (checkBoxRegistry.Checked)
{
registryKey().SetValue(Application.ProductName, Application.ExecutablePath);
}
else
{
registryKey().DeleteValue(Application.ProductName, false);
}
}
}
}
Another method is to add an application shortcut to the Windows Startup folder.
Continue reading