17
votes

Each time I restart my computer, I have to rebuild all my AHK Scripts so the keyboard shortcuts will work.

For instance, I have a script that assigns Ctrl+j to set up an instance of the MEAN stack and open my web site. After restarting my computer, pressing ^j does nothing until I go into Sublime and ^b (Build). I could build from AHK, but I do a lot of work in Sublime, so it's easier to build there.

How can my AHK Scripts automatically build on startup?


What I've tried so far:
  • Looking to build a post startup, startup script: This Is concerned with using an AHK script to start many programs on starup. I use Windows' Task Manager > Startup to do this, thus has nothing to do with making. I want to not have to rebuild all my scripts after every restart.

  • Windows 10 - run script on windows startup problem: This assumes the start script is already written and implemented. However, it doesn't appear to give the script.

  • AutoHotKey FAQ: I eventually found a solution here, but it took a long time to dig through the questions so I figured I'd post a question anyway to help others who run into this.

4
"After restarting my computer, pressing ^j does nothing until I go into Sublime and ^b ..." That should probably be the actual question to ask about. XY problem.user4157124
Not sure you want to "build" the script and not simply launch/start it. You can launch it at startup by adding a shortcut to it in your startup folder (req. you have set ahk.exe as default to open .ahk files)Thierry Dalon

4 Answers

27
votes

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

or

2- Start > Programs > Startup

or

3- Open Windows' Run application (Windows + r) write shell:startup in the edit field and click on the 'ok' button.

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

5
votes

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
0
votes

As a Windows 7 user, I have limited experience with Windows 10. I have heard that W10 can be finicky with regard to running programs underground administratie or limited user. In W7, you just add the .AHK file link to the startup dir.

0
votes

To allow the script to automate administrative programs without running as admin, here're the required steps:

  1. When installing AHK, check the "Add 'Run with UI Access' to context menus" option.
  2. After installation, find AutoHotkeyU64_UIA.exe on your disk.
  3. Open the .ahk script's properties, change the "Open with" option to the AutoHotkeyU64_UIA.exe you just found.
  4. Create a shortcut to this script.
  5. Open %APPDATA%\Microsoft\Windows\Start Menu\Programs\Startup in the file explorer.
  6. Move that shortcut to this folder.

And you're done.


How does it work?

The "Add 'Run with UI Access' to context menus" option provides a workaround for common UAC-related issues by allowing the script to automate administrative programs without running as admin.

Reference: Run with UI Access.