Search code examples
adminautohotkeystartup

Run AHK script as admin on startup


I have four AHK scripts which run on startup, as they have shortcuts placed in my startup folder. How can I make them run as admin?

What I've tried:

I've tried changing their properties to be run as admin, but they just don't run (when I do that).

I've tried changing their shortcuts' properties to be run as admin, but they too just don't run (when I do that).

I've looked at this reddit post on the topic, but I don't know how to implement that code in the scripts.

I've tried creating a basic C++ application which runs them with system("start path\\to\\script"), but it wouldn't compile.

In case it matters, the scripts in question are ahk-active-screenshot, CtrlAlt_Switch.ahk, Kill.ahk, and a modified version of this search script.


Solution

  • You can 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.