Running AHK via Task Scheduler with upgraded privileges

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
User avatar
JoeSchmoe
Posts: 129
Joined: 08 Dec 2014, 08:58

Running AHK via Task Scheduler with upgraded privileges

09 Feb 2018, 13:09

Heya, folks.

I've been running my "AlwaysRunning" script for years using Task Scheduler, but I've noticed that sometimes the icon doesn't appear in the task bar and sometimes other scripts can't find the AlwaysRunning window with WinExist.

Has anyone else run AHK using Task Scheduler? If so, what settings do you use? I set it to run with highest privileges, triggered by my login.

Also, now I'm trying to figure out how to get it to run with Admin privileges under a non-admin account. I actually hide my admin password, so I don't want to have to type it into a elevation prompt. I'd rather just go without the functionality that needs admin access.

For this second question, I tried having the task be run under the admin account, but had it be triggered by the non-admin account's login. However, when it asked me for the admin's login password, it rejected it, which confused me. Is this the right way to go about it?
lexikos
Posts: 9583
Joined: 30 Sep 2013, 04:07
Contact:

Re: Running AHK via Task Scheduler with upgraded privileges

11 Feb 2018, 01:03

Unless you have set the task to run as the current user and with "Run only when user is logged on", the process will not run interactively. It will not be able to see or create windows in the current session, and hotkeys, Send, etc. will not work. It would be possible to work around this by running multiple processes and having them communicate (with one performing admin work and the other interacting with the user's session). I know of no other solution.

I know of no reason that it would sometimes succeed and sometimes fail, unless you are "sometimes" changing the task settings.
However, when it asked me for the admin's login password, it rejected it, which confused me.
If by "it" you mean Task Scheduler's user interface, and you've set the admin user under "When running the task, use the following user account", you probably got the password wrong (or you selected the wrong account, but it would still have to be a valid account). I can think of no other explanation.
User avatar
JoeSchmoe
Posts: 129
Joined: 08 Dec 2014, 08:58

Re: Running AHK via Task Scheduler with upgraded privileges

11 Feb 2018, 23:11

Thank you very much, Lexikos. It's nice to have such a clear answer.

It looks like it is therefore impossible to get Autohotkey to run interactively with admin privileges form a non-admin account. I say this because the following post suggests to get admin privileges from a non-admin account, you have to run as another user. As per Lexikos, this will prevent AHK from running interactively
With the UAC, users of the admin group have 2 tokens. The filtered token represents standard user rights. This token is used to create the shell. So you have standard user rights. When you click an executable and select "run as administor", the full token is used which contains admin rights.

When you now configre Task scheduler and select "Run with the highest privileges", the full token (admin rights) is used. This only works if the user is in the admin group, because only those users have 2 tokens. When you want to run a programm with admin rights from a standard user account, you have to select "run whether the user is logged on or not" and select a user which is member of the admingroup.

Source: https://social.technet.microsoft.com/Fo ... progeneral

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Descolada, sharonhuston and 223 guests