'How to build AHK scripts automatically on startup?
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.
Solution 1:[1]
Run at startup in Windows 10:
- Compile the script to *.exe
- Put the shortcut of that exe in startup folder "%appdata%\Microsoft\Windows\Start Menu\Programs\Startup"
- 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:
- Go to ahk script and mark it run as admin.
- 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.
- 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
Solution 2:[2]
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.
Solution 3:[3]
Open note pad or any other text editor
write
Start "" "C:\ahk\yourdirectory\yourahk.ahk"press save as
navigate to
%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startupname the filename
anything.bat
Solution 4:[4]
To allow the script to automate administrative programs without running as admin, here're the required steps:
- When installing AHK, check the "Add 'Run with UI Access' to context menus" option.
- After installation, find
AutoHotkeyU64_UIA.exeon your disk. - Open the
.ahkscript's properties, change the "Open with" option to theAutoHotkeyU64_UIA.exeyou just found. - Create a shortcut to this script.
- Open
%APPDATA%\Microsoft\Windows\Start Menu\Programs\Startupin the file explorer. - 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.
Solution 5:[5]
- Open windows run (win+r) and type “shelll:startup”
- Copy paste the ahk file into there
- Close the folder
And that‘s all!
Solution 6:[6]
A simple solution without writing any code, using the Windows Task Scheduler, set the script to start when the user logs on. If it is set to system startup it will error because it is too early.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | |
| Solution 2 | Robert Ilbrink |
| Solution 3 | Mo D Genesis |
| Solution 4 | |
| Solution 5 | ouflak |
| Solution 6 | weiya ou |
