AutoHotkey (AHK) is a scripting language for Windows that helps automate repetitive tasks, create hotkeys, manage windows, etc. Since they automate things, you might also want these AHK scripts to run automatically when Windows starts, so that you don’t have to manually start them every time you restart your computer.
In Windows 11 and 10, you can do this mainly through two methods: the Startup Folder method and the Task Scheduler method. Both are pretty efficient but serve different purposes. In this guide, we’ll explain each method so you can decide which one to use to get your AHK scripts running automatically at startup.
Page Contents
How to correctly use the startup folder to start an AutoHotkey script on Windows startup
The Startup Folder is a special place in Windows where you can put shortcuts to apps you want to run automatically when you log into your computer. This method is actually simple but often causes confusion. The following steps will show you how to correctly put the AHK script into the startup folder to let it auto-start on Windows startup.
Also see: Where is the Startup Folder in Windows 11/10 for All Users
-
- First, find your AHK script. Go to the folder with your
.ahk
file. - Right-click on your AHK script and choose “Create shortcut”. This will make a shortcut of the script in the same folder.
- Now, press the Windows + R keys together. This opens the “Run” dialog box.
- First, find your AHK script. Go to the folder with your
- In the “Run” dialog box, type (or copy-paste):
shell:startup
- Click “OK” or press Enter. This will open the Startup folder for your user account.
- Now, just drag and drop the shortcut you made in step 2 into this Startup folder.
- That’s it. Your AHK script will now run every time you log into your Windows account.
If you want your script to run for all users, use the command shell:common startup
in step 4. This will open the common startup folder, and any shortcuts placed here will run for all users on the system.
Also, if you move the original .ahk
file, the shortcut might stop working. Keep the original file in its place.
Run your AHK script on startup as administrator
If you also need to run the AHK script with administrator’s privileges, there are some extra steps you need to take.
- In the Startup folder, right-click on the AHK script shortcut you added and select “Properties”.
- Go to the “Shortcut” tab in the “Properties” window.
- Click the “Advanced” button at the bottom-right of this window.
- In the pop-up window, check the box labeled “Run as administrator”.
- Click “OK” to close the Advanced Properties window, then click “OK” again to exit the Shortcut Properties window.
- On your next system startup, Windows will ask for permission (due to User Account Control) to run the script with admin rights. Allow this, and your script will start with elevated privileges.
Be careful when allowing scripts (or any app) to run as an admin. Make sure the script is safe and not actually harmful.
Schedule an AutoHotKey script to run on Windows startup using the Task Scheduler
The Task Scheduler is more flexible than the Startup Folder because it lets you set conditions, choose different triggers, and set user permissions. This is useful for scripts that need to run with admin rights or at specific times.
- Press the Windows key and type “Task Scheduler”. Click on the Task Scheduler app that shows up.
- In the right pane, click on “Create Basic Task…”.
- In the “Name” box, give your task a descriptive name, like “My AHK Script Startup”. You can also add an optional description. Click “Next”.
- For the trigger, you have a couple of choices:
- Choose “When I log on” if you want the script to run every time you log into your computer. This is good for personal scripts that are user-specific.
- Or, choose “When the computer starts” if you want the script to run as soon as the computer boots up, even before anyone logs in. This is useful for scripts that have system-wide effects or need to start before any user logs on.
After choosing, click “Next”.
- For the action, choose “Start a program”. Click “Next”.
- In the “Program/script” box, type or browse to the AutoHotKey executable (usually in
C:\Program Files\AutoHotkey\AutoHotkey.exe
or similar). - In the “Add arguments (optional)” box, type the path to your
.ahk
script in double quotes. For example:
"C:\Path\To\YourScript.ahk"
Click “Next”. - Check your settings in the summary page, and if everything looks good, click “Finish”.
Other advanced options you might want to use
- If you need your script to run with admin rights, before finishing the task creation, click on “Open the Properties dialog for this task when I click Finish”. In the properties dialog, under the “General” tab, check “Run with highest privileges”.
- Task Scheduler also allows you to run tasks at specific times, under specific conditions, or when specific events happen. You can set these under the “Triggers”, “Actions”, “Conditions”, and “Settings” tabs in the task properties dialog.
Related resource: How to Run Batch File Without the CMD Window
Some common issues
Although the methods above should usually get your AHK script to start automatically on startup, you might face some issues.
Script doesn’t run on startup
- Make sure both the AHK executable and the script file paths are correct. If you’ve moved the script or the AutoHotKey installation, you might need to update the paths.
- Some scripts need admin rights. Try setting the shortcut to run as admin through its properties window. Also, enable “Run with highest privileges” if you use the task scheduler method.
- Your script might need other files or programs. Make sure they’re available and in the expected location when the script starts.
Script runs but doesn’t function as expected
- Some scripts depend on other services or programs that start with Windows. You can add a delay to your script using the
Sleep, DurationInMilliseconds
command in AHK. For example,Sleep, 10000
will delay your script by 10 seconds. - If your script works with specific windows or apps, make sure they are available and in the expected state when the script runs.
Task Scheduler problems
- In the Task Scheduler, you can see the last run result and the status of the task. This can provide clues if there’s an issue.
- Task Scheduler keeps a history of when tasks are triggered and if they encountered any issues. This helps diagnose problems.
- If you’ve set specific conditions for the task (like running only when on AC power), make sure those conditions are met.