105
Thanks to everyone for responding so fast. Joel, I used your option 2 and added a registry key to the "Run" folder of the current user. Here's the code I used for anyone else who's interested.
using Microsoft.Win32;
private void SetStartup()
{
RegistryKey rk = Registry.CurrentUser.OpenSubKey
("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true);
if (chkStartUp.Checked)
rk.SetValue(AppName, Application.ExecutablePath);
else
rk.DeleteValue(AppName,false);
}
Several options, in order of preference:
HKey_Current_User\Software\Microsoft\Windows\CurrentVersion\Run registry key. The issue here is it only applies to the current user. Setting it for other users individually can be done, including the default/template user, but only by loading those registry hives one by one (including the template at C:\Users\Default\ntuser.dat), and I'm not sure that's even possible using normal programming techniques.HKey_Local_Machine\Software\Microsoft\Windows\CurrentVersion\Run registry key. The only problem here is it requires write access to a part of the registry which isn't often available to standard-privileged users.This answer is older now. Since I wrote this, Windows 10 was released, which changes how the Start Menu folders work... including the Startup folder. It's not yet clear to me how easy it is to just add or remove a file in that folder without also referencing the internal database Windows uses for these locations.