AutoHotkey is a free, open-source scripting platform for Windows. You can use it to automate repetitive, tedious tasks or to turn just about any action into a keyboard shortcut. Once a script has been written and compiled there may be a need to have it automatically start with Windows. There are two ways to do this: startup folders or the registry. Both techniques are explained below:
Use a Shortcut
This will create a shortcut in the common startup folder to launch an application:
1 2 3 4 5 6 7 |
SplitPath, A_Scriptname, , , , OutNameNoExt LinkFile=%A_StartupCommon%%OutNameNoExt%.lnk FileCreateShortcut, %A_ScriptFullPath%, %LinkFile% If ErrorLevel <> 0 { MsgBox Could Not Create } |
To create it in the user’s startup folder replace
A_StartupCommon with
A_Startup.
Start in the Registry
This will use the registry to launch the program. Below, a check is being done as to whether the script is compiled or not. It will still work either way but this way will only touch the registry when out of test mode.
WindowsStart is a just a variable containing 1 or 0, based off the user’s settings.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
SplitPath A_ScriptFullPath, , , ext Compiled := (ext = "exe") if(Compiled) { if(WindowsStart = 1) { RegWrite, REG_SZ, HKEY_CURRENT_USER, SoftwareMicrosoftWindowsCurrentVersionRun, SoundLynk, %A_ScriptFullPath% } else { RegDelete, HKEY_CURRENT_USER, SoftwareMicrosoftWindowsCurrentVersionRun, SoundLynk } } |