1
votes

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.

2

2 Answers

2
votes

Find the UIA version of autohotkey on your machine. For me it is at C:\Program Files\AutoHotkey\AutoHotkeyU64_UIA.exe.

In your startup folder, create a new shortcut (probably one for each of the scripts you want) as follows (replacing paths as appropriate):

  • Target: "C:\Program Files\AutoHotkey\AutoHotkeyU64_UIA.exe" "D:\path\to\script.ahk"
  • Start in: "C:\Program Files\AutoHotkey"

This launches your script as an admin using the UIA version of AHK on startup.

2
votes

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.