How to build AHK scripts automatically on startup?

Run at startup in Windows 10:

  1. Compile the script to *.exe
  2. Put the shortcut of that exe in startup folder "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup"
  3. That's all. Do NOT set it to run as admin. Programs in Win10 don't run at startup which are marked as run as admin.

Run Script as admin at Startup in Windows 10:

  1. Go to ahk script and mark it run as admin.
  2. Create the VBScript using a text editor
'put it in startup folder to run the mentioned ahk script at startup
Set WshShell = CreateObject("WScript.Shell" )    
WshShell.Run """C:\Users\jerry\Downloads\scripts\some_script.ahk""", 0 'Must quote command if it has spaces; must escape quotes   
Set WshShell = Nothing

Replace C:\Users\jerry\Downloads\scripts\some_script.ahk with the path to your script with extension and save it as .vbs.

  1. Place this .vbs script at startup folder %appdata%\Microsoft\Windows\Start Menu\Programs\Startup

PS: My fav AHK scripts: https://gourav.io/blog/autohotkey-scripts-windows


Simply add a shortcut (don't need to be the actual file) of your script in the Windows 'Startup' folder.

Three ways to get there:

1- In Windows Explorer, go to %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup (for current user startup list) or %ALLUSERSPROFILE%\Microsoft\Windows\Start Menu\Programs\Startup (for every user startup list)

or

2- Open Windows' Run application (Windows + r) write shell:startup (current user) or shell:common startup (every user) in the edit field and click on the 'ok' button.

or

3- Start > Programs > Startup (old Windows versions)


In AutoHotKey you can access this folder with the Built-in Variables %A_Startup% (current user) or %A_StartupCommon% (every user)

To create the (current user) shortcut automatically from your script, use the following line:

FileCreateShortcut, %A_ScriptFullPath%, %A_Startup%\shortcutname.lnk

To do the same for all users, use this line instead:

FileCreateShortcut, %A_ScriptFullPath%, %A_StartupCommon%\shortcutname.lnk

(in the case of having a file with the same name in the folder, the file would be overwritten)


ps: Win10 blocks scripts in startup with AHK running as admin... read the comments of this post for extra info.

Tags:

Autohotkey