AutoHotkey (often abbreviated as AHK) is a powerful scripting language for Windows that allows users to automate repetitive tasks, create hotkeys, manipulate windows, and much more. One of the most common desires among AHK users is to have their scripts run automatically on Windows startup.
In Windows 11 and 10, there are primarily two methods to achieve this: the Startup Folder method and the Task Scheduler method. Both are efficient, but they serve different needs. In this guide, we’ll discuss each method, providing a step-by-step walkthrough to get your AHK scripts running automatically at startup.
How to correctly use the Startup folder to start an AutoHotkey script on Windows startup
The Startup Folder is a special location in Windows where you can place shortcuts to applications that you want to run automatically when you log into your computer. This method is straightforward and easy to set up.
- First, you’ll need to locate your AHK script. Navigate to the folder containing your
- Right-click on your AHK script and choose “Create shortcut”. This will produce a shortcut of the script in the same directory.
- Now, press the Windows + R keys simultaneously on your keyboard. This will open the “Run” dialog box.
- In the “Run” dialog box, type (or copy-paste) the following:
- Click “OK” or press the Enter key. This action will open the Startup folder for your user account.
- Now, simply drag and drop the shortcut you created in step 2 into this Startup folder.
- That’s it! Your AHK script will now run every time you log into your Windows account.
To run your AHK script on startup as administrator:
- Within the Startup folder, right-click on the AHK script shortcut you just added and select “Properties”.
- Navigate to the “Shortcut” tab in the “Properties” window.
- Click the “Advanced” button located at the bottom-right of this window.
- In the pop-up window, tick the box labeled “Run as administrator”.
- Click “OK” to close the Advanced Properties window, followed by another “OK” to exit the Shortcut Properties window.
- Upon your next system startup, Windows will prompt for permission (due to User Account Control) to run the script with administrative rights. Grant this permission, and your script will launch with elevated privileges.
- If you wish your script to run for all users, use the command
shell:common startupin step 4 instead. This will open the common startup folder, and any shortcuts placed here will run for all users on the system.
- Remember that if you move the original
.ahkfile, the shortcut might stop working. Always ensure the original file remains in its location.
- Take caution when allowing scripts (or any application) to run as an administrator. Ensure the script is free from malicious intent or actions.
Schedule an AutoHotKey script to run on Windows startup using the Task Scheduler
Using the Task Scheduler offers more flexibility than the Startup Folder. It allows you to set conditions, choose different triggers other than startup, and specify user permissions. This is especially useful for scripts that need to run with elevated privileges or at specific intervals.
- Press the Windows key and type “Task Scheduler”. Click on the Task Scheduler app that appears in the search results.
- 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 provide an optional description. Click “Next”.
- For the trigger, you have a couple of relevant choices:
- Select “When I log on” if you want the script to run every time you log into your computer. This is suitable for most personal scripts that are user-specific.
- Alternatively, select “When the computer starts” if you want the script to run as soon as the computer boots up, even before anyone logs in. This might be useful for scripts that have system-wide effects or need to start before any user logs on.
After making your selection, click “Next”.
- For the action, select “Start a program”. Click “Next”.
- In the “Program/script” box, type or browse to the location of the AutoHotKey executable (typically located in
C:\Program Files\AutoHotkey\AutoHotkey.exeor similar).
- In the “Add arguments (optional)” box, type the path to your
.ahkscript, enclosed in double quotes. For example:
- Review your settings in the summary page, and if everything looks correct, click “Finish”.
- If you need your script to run with elevated privileges (as an administrator), before finishing the creation of the task, 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 for running tasks at specific intervals, under specific conditions, or even when specific events occur. These options can be configured under the “Triggers”, “Actions”, “Conditions”, and “Settings” tabs in the task properties dialog.
- Using the Task Scheduler ensures your script can run with elevated permissions if needed. This is essential for scripts that might need to interact with protected system functions or files.
- It’s always a good idea to test your scheduled task after creating it. Right-click on the task in the Task Scheduler main window and select “Run” to see if your AHK script starts correctly.
Related resource: How to Run Batch File Without the CMD Window
Troubleshooting common issues
While the aforementioned methods are generally reliable, you may encounter issues occasionally. Here are some common problems and their solutions when trying to start AHK scripts on Windows 11/10 startup:
Script doesn’t run on startup:
- Check the path: Ensure that 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 adjust the paths.
- Run as administrator: Some scripts require elevated privileges. Try setting the shortcut to run as administrator through its properties window. Also, remember to enable the “Run with highest privileges” if you are using the task scheduler method
- Dependencies: Your script might rely on other files or programs. Ensure they’re available and in the expected location when the script starts.
Script runs but doesn’t function as expected:
- Delay on startup: Some scripts might be dependent on other services or programs that start up with Windows. You can add a delay to your script using the
Sleep, DurationInMillisecondscommand in AHK. For instance,
Sleep, 10000will delay your script by 10 seconds.
- Context-sensitive actions: If your script works with specific windows or applications, ensure they are available and in the expected state when the script runs.
Task Scheduler issues:
- Check task status: 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.
- Review task history: Task Scheduler keeps a history of when tasks are triggered and if they encountered any issues. This is particularly useful for diagnosing problems.
- Check conditions: If you’ve set specific conditions for the task (like running only when on AC power), ensure those conditions are met.
AutoHotKey scripts are incredibly versatile, and there’s no necessity to compile them to have them run on Windows startup. Both the Startup folder method and the Task Scheduler method are effective ways to get your AHK scripts running automatically. However, if you ever encounter issues or need more control and flexibility, the Task Scheduler method is generally more recommended.