Get AutoHotkey Script To Run As Admin At Startup
- by deadlydog
A few weeks back I posted some problems with running AutoHotkey (AHK) in Windows 8, and that the solution was to run your AHK script as admin. I also showed how to have the script start automatically when you logged into Windows. What I didn’t realize at the time though was that the method only worked because I had disabled UAC in the registry (which prevents most Metro apps from working in Windows 8, and likely isn’t acceptable for most people). So here is a Windows 8, UAC-friendly method to accomplish the same task (also works in previous versions of Windows). The trick is to use the Task Scheduler: 1. Open the Task Scheduler (also known as “Schedule tasks” in Windows 8 Settings). 2. Create a new Basic Task. 3. Give it a name and description (something like “launch AutoHotkey script at login”), and then specify to have it run “When I log on”. Then specify that you want it to “Start a program”, and then point it towards your AutoHotkey script. Before you finish the wizard, check off “Open the Properties dialog for this task when I click Finish”. 4. When that Properties dialog opens up, go to the Conditions tab and make sure none of the checkboxes under the Power category are checked off; this will ensure the script still launches if you are on a laptop and not plugged into AC power. 5. Now here is the important part; To have your script “Run as admin”, on the General tab check off “Run with highest privileges”. Now your AHK script should start automatically as soon as you log into Windows; even when UAC is enabled 6. If your AHK script uses an #Include statement to include other files, you may get an error similar to this one when your task runs: “#Include file … cannot be opened. The program will exit.” The solution to this is to tell your AHK script to start in the same directory as the file that you want to include. So you will need to edit your scheduled task’s Action to specify the Start In directory. Happy coding!