When you check the box, would use
FileCreateShortcut to stick a shortcut to the script in the Startup folder. This varies from Windows to Windows. On Windows 8.1, it is in %appdata%\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\
Then when you uncheck the box, I would delete that Shortcut with
FileDelete.
This is code I have (I use #Include, pointing to this script, so that I can add a toggle feature to my scripts right-click menu to decide if I want this script to launch on startup or not.) You may be able to adapt it to your purposes. Focus on the StartUpToggle label; Basically where I have
If ErrorLevel, that is where you would check the value of your checkbox being 0 or 1.
Code: Select all
Menu, Tray, UseErrorLevel
If FileExist(startUpDir:=("C:\Users\" A_UserName "\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\" A_ScriptName " - Shortcut.lnk"))
Menu, Tray, Add, Remove from StartUp, StartUpToggle
else
Menu, Tray, Add, Add to StartUp, StartUpToggle
GoSub, SkipLabel_StartUp
return
StartUpToggle: ; I could really use a better way to know the name of the menu item that was selected
; Using now errorlevel to determine if the menu item name exists
Menu, Tray, Rename, Remove from StartUp, Add to StartUp
If ErrorLevel ; Remove from StartUp doesn't exist. So Add to StartUp does. So we're adding this script to startup
{
FileCreateShortcut, %A_ScriptFullPath%, %startUpDir%
Menu, Tray, Rename, Add to StartUp, Remove from StartUp
}
else ; we successfully renamed the Remove from StartUp, which means that was selected, so we need to remove the script from startup
FileDelete, %startUpDir%
return
SkipLabel_StartUp: