Auto-Loading AutoHotkey Scripts When Booting Windows

Add Shortcuts to Your Windows Startup Folder to Automatically Run Your Most Important Scripts

Every AutoHotkey user keeps a few favorite scripts at hand. Some people put them in one big master AHK file—auto-loading it when Windows boots. Others may use Windows Task Scheduler to initiate the apps. (See the “Windows Task Scheduler to Elevate Script Privileges” section of Chapter 16.1.4 of Jack’s Motley Assortment of AutoHotkey Tips.) Even more, add individual shortcuts to the Windows Startup folder for the preferred scripts. Each method has its advantages and disadvantages. In this blog, I visit AutoHotkey techniques for adding shortcuts to the Windows Startup folder.

Recently, a reader pointed out that the link for the AutoStartupToggle.ahk script at the Free AutoHotkey Scripts page pointed to the wrong script. I repaired the link then took a closer look at the script.

After selecting an AutoHotkey script (.ahk) or compiled app (.exe) in Windows File Explorer, the Ctrl+Win+3 key combination creates a shortcut in the Startup folder—auto-loading the script on bootup. If the matching shortcut exists in the Startup folder, that same Hotkey combination removes it. While this barebones routine works fine, I began considering the implications of using the Startup folder for all my regular scripts. This prompted me to dig deeper into the possibilities.

Advantages and Disadvantages to Using the Windows Startup Folder

I’ve combined many of my AutoHotkey script into one master script I named ce_edit.ahk—compiling it into ce_edit.exe. (It appears in the MsgBox window—called by Ctrl+Win+4 and shown above—as a shortcut in the Windows Startup folder. Frankly, until calling it to my attention, I had forgotten about the AutoStartupToggle.ahk script.) For many of the other listed scripts, I created shortcuts for each .ahk file—moving it into my Startup folder:

C:\Users\Jack\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup

The major advantage to using Startup folder shortcuts is that you don’t need to figure out how to combine the individual scripts with other AutoHotkey scripts—either directly or through the #Include directive.

On the downside, every time you insert another shortcut targeting an AutoHotkey script into Startup, you also add an icon to the Windows System Tray. It can get pretty cluttered and confusing—especially when they all display the same green AutoHotkey logo.

You could turn off icon in the System Tray:

Menu, Tray, NoIcon

but that leaves you in the dark without an easy method for either suspending or exiting the app via its right-click menu. Over the next couple of blogs, I plan to explore some options for managing AutoHotkey shortcuts in the Startup folder. But first, I want to introduce a small improvement to the original AutoStartupToggle.ahk script which you may find useful in other non-related scripts. (Discussed in Chapter 13.1.6 “Automatically Launch Apps at Windows Startup” of Jack’s Motley Assortment of AutoHotkey Tips.)

Trap Accidental Removal of Shortcuts

The file creation toggle works great for adding and removing shortcuts to and from the Startup folder. However, you may not remember whether or not you’ve added the file to the folder. You could open the Startup folder and look for yourself, but it makes life easier when the AutoHotkey script updates you with file status before you make the change. This simple trick works for many applications where knowing status information saves time.

Toggles often have a preferred or default state. In this case, an existing Startup shortcut indicates that preferred status. While creating a new shortcut can run without hindrance, deleting one requires another level of caution—especially if you’ve manually modified the shortcut parameters. To increase the level of attention in the deletion routine, we add a trap.

When I want to create a new shortcut (low risk), it can occur immediately. I find no need to change that part of the script. Yet, if I forget that I previously added the shortcut, I don’t want to accidentally delete it—just to add it back again. I’ve inserted a trap—preventing the deletion unless I give the go-ahead:

^#3::                 ; Activates with CTRL+WIN+3
  Clipboard =    ; Empties Clipboard
  Send, ^c          ; Copies filename and path
  ClipWait 0       ; Waits for copy
  SplitPath, Clipboard, Name, Dir, Ext, Name_no_ext, Drive
  IfExist, %A_Startup%\%Name_no_ext%.lnk
    MsgBox, 4, Found in Startup Folder
          , %Name% exists in Startup folder! Remove?
      IfMsgBox Yes
        FileDelete, %A_Startup%\%Name_no_ext%.lnk
     MsgBox, %Name% removed from the Startup folder.
    FileCreateShortcut, "%clipboard%"
           , %A_Startup%\%Name_no_ext%.lnk
           , %Dir%   ; Line-wrapped using AutoHotkey line continuation
    MsgBox, %Name% added to Startup folder for auto-launch with Windows.

The highlighted portion of the script pops-up a MsgBox telling me that the shortcut already exists—offering the option to delete it or cancel the process (Return). Now the Hotkey instantly tells me whether or not I need to continue the procedure—a small, yet important change.

I see possibilities for addressing the weaknesses of AutoHotkey Startup shortcuts. I need a management system for viewing and accessing my Startup files. I don’t yet know exactly how I’ll do it, but I plan to create a utility for viewing (and possibly controlling) the AutoHotkey scripts loaded through the Startup folder while eliminating the numerous AutoHotkey icons in the System Tray. I expect that I’ll learn a few things along the way.

Click the Follow button at the top of the sidebar on the right of this page for e-mail notification of new blogs. (If you’re reading this on a tablet or your phone, then you must scroll all the way to the end of the blog—pass any comments—to find the Follow button.)


This post was proofread by Grammarly
(Any other mistakes are all mine.)

(Full disclosure: If you sign up for a free Grammarly account, I get 20¢. I use the spelling/grammar checking service all the time, but, then again, I write a lot more than most people. I recommend Grammarly because it works and it’s free.)

Find my AutoHotkey books at ComputorEdge E-Books!

Find quick-start AutoHotkey classes at “Robotic Desktop Automation with AutoHotkey“!

2 thoughts on “Auto-Loading AutoHotkey Scripts When Booting Windows

  1. I’ve always used the registry for things I want to start automatically in Windows but I see how this could be a more user-friendly method.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s