Elevated AHK script refuses to recieve runtime arguments from PowerShell

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Ralf_Reddings200244
Posts: 84
Joined: 11 Mar 2023, 14:16

Elevated AHK script refuses to recieve runtime arguments from PowerShell

Post by Ralf_Reddings200244 » 07 Jun 2023, 14:32

For a long time I have been using this excellent function by SKAN RunAsTask() - Auto-elevates script without UAC prompt - AutoHotkey Community

It lets you always run a script as elevated, every single time without being prompted by UAC (You will be prompted once, for every new script)
You simply need to place RunAsTask() at the top of the script.

I just discovered, that you cannot pass command line arguments to a script that is going to run as elevated.
I am absolutely gutted, this throws a wrench at so many of my programs and tools.

Code: Select all

RunAsTask()
MsgBox, % A_args[1]
If I have a .ahk script consisting of only the above and in a PowerShell terminal invoking:

Code: Select all

. "C:\Temp\MyScript.ahk" "Hello World"
The script never receives this message, the message box is empty.

The only way I can get the script to receive Hello World is by uncommenting runAsTask() or running PowerShell as Admin.

Neither of which as an option for me, I use the terminal allot, I cannot imagine doing so as Admin, Its just too dangerous.

I also cannot cannot run scripts as un elevated as then they wont be able to interact with elevated processes

I don't even know what is the culprit, is it RunAsTask? Is it a general thing to do with UAC? Has anyone come across this issue before?
I would really appreciate any ideas on how to solve this issue or any insight into the cause. Thanks!

Return to “Ask for Help (v1)”