Stupid question maybe...
The runastask works great... but in my code my next line has to start but without admin rights is there a simple solution for this
because if i punt for example the line run app3.exe it aso starts with admin rights, but now it has to run in normal users mode
runastask.stop or exit ?
RunAsTask() - Auto-elevates script without UAC prompt
Re: RunAsTask() - Auto-elevates script without UAC prompt
The above solution doesn't work for me.
In addition, I noticed something peculiar.
When I run an ahk file from VSCode there's no UAC prompt
Whereas if I were to run directly by double clicking in file explorer or using one AHK script to run another with Run, scriptname.ahk then the UAC prompt appears
In addition, I noticed something peculiar.
When I run an ahk file from VSCode there's no UAC prompt
Whereas if I were to run directly by double clicking in file explorer or using one AHK script to run another with Run, scriptname.ahk then the UAC prompt appears
Re: RunAsTask() - Auto-elevates script without UAC prompt
Hey I use your script and it works fine for most of the time but I also get this message box
if I already have a script running as elevated, running it again from explorer window(with RunAsTask) causes the above message box to show.
Its frustrating as I do this all the time, for example to refresh a running script.
Does anyone have any workarounds? Thanks.
if I already have a script running as elevated, running it again from explorer window(with RunAsTask) causes the above message box to show.
Its frustrating as I do this all the time, for example to refresh a running script.
Does anyone have any workarounds? Thanks.
Re: RunAsTask() - Auto-elevates script without UAC prompt
That will be the the behaviour even without RunAsTask().
Edit:
The following workaround should work:
https://www.autohotkey.com/boards/viewtopic.php?p=72017#p72017
Re: RunAsTask() - Auto-elevates script without UAC prompt
Thats excellent SKAN. it did just the trick. I did not know that it was the case even without your script, I stand corrected.
I love your tools and they proven to be a boon to me and my unknowing sister. Much thanks!
I love your tools and they proven to be a boon to me and my unknowing sister. Much thanks!
Re: RunAsTask() - Auto-elevates script without UAC prompt
Hi,
I'm new to AHK.
My problem is "very simple" :
I have a .ahk script which I need to run on startup (Windows 10).
I placed the script file into the startup dir of Windows. Doing so, the script is launched after login, but the problem is I am prompted every single time by UAC to confirm running it.
Searching around I was pointed to this thread. The problem is I really didn't get how to make use of RunAsTask.
Could you walk me through it "step by step" ?
At the moment I simply have the .ahk file.
Thanks
I'm new to AHK.
My problem is "very simple" :
I have a .ahk script which I need to run on startup (Windows 10).
I placed the script file into the startup dir of Windows. Doing so, the script is launched after login, but the problem is I am prompted every single time by UAC to confirm running it.
Searching around I was pointed to this thread. The problem is I really didn't get how to make use of RunAsTask.
Could you walk me through it "step by step" ?
At the moment I simply have the .ahk file.
Thanks
Re: RunAsTask() - Auto-elevates script without UAC prompt
Does this script make any changes to the Windows Registry?
Last edited by carno on 26 Jul 2022, 12:50, edited 1 time in total.
Re: RunAsTask() - Auto-elevates script without UAC prompt
Thank you Skan! Any idea why this would work fine on an uncompiled script but on the same script compiled it closes the original script as it is supposed to but doesnt start a new,elevated one?
Re: RunAsTask() - Auto-elevates script without UAC prompt
I am also interested in this "step by step" walk-through as my coding is getting a bit rusty.Nite wrote: ↑29 Sep 2021, 05:40Hi,
I'm new to AHK.
My problem is "very simple" :
I have a .ahk script which I need to run on startup (Windows 10).
I placed the script file into the startup dir of Windows. Doing so, the script is launched after login, but the problem is I am prompted every single time by UAC to confirm running it.
Searching around I was pointed to this thread. The problem is I really didn't get how to make use of RunAsTask.
Could you walk me through it "step by step" ?
At the moment I simply have the .ahk file.
Thanks
-
- Posts: 4
- Joined: 25 Jan 2018, 05:35
- Contact:
Re: RunAsTask() - Auto-elevates script without UAC prompt
Worked like a charm!
Thanks so much, I stumbled across this and tried with my Disable AltTab script (I play a lot of Apex, so need to run this to avoid accidentally pressing Windows key / Alt Tab stuff. Doesn't kick in unless it's running as an Admin because Apex does).
I can see in Task Manager it's elevated (can choose "Elevated" from the Details visible columns). As a thank you, I don't mind sharing my Disable AltTab script for you all You can use the F8 key to Suspend or Resume it too!
I had to redirect all separate hotkeys to Return, otherwise it would still exit the game if another was pressed!
Thanks so much, I stumbled across this and tried with my Disable AltTab script (I play a lot of Apex, so need to run this to avoid accidentally pressing Windows key / Alt Tab stuff. Doesn't kick in unless it's running as an Admin because Apex does).
I can see in Task Manager it's elevated (can choose "Elevated" from the Details visible columns). As a thank you, I don't mind sharing my Disable AltTab script for you all You can use the F8 key to Suspend or Resume it too!
I had to redirect all separate hotkeys to Return, otherwise it would still exit the game if another was pressed!
- Attachments
-
- Disable AltTab.ahk
- (407 Bytes) Downloaded 92 times
Re: RunAsTask() - Auto-elevates script without UAC prompt
Your script has an error, in these lines:
Code: Select all
CmdLine := ( A_IsCompiled ? "" : """" A_AhkPath """" ) A_Space ( """" A_ScriptFullpath """" )
TaskName := "[RunAsTask] " A_ScriptName " @" SubStr( "000000000" DllCall( "NTDLL\RtlComputeCrc32"
, "Int",0, "WStr",CmdLine, "UInt",StrLen( CmdLine ) * 2, "UInt" ), -9 )
Code: Select all
CmdLine := ( A_IsCompiled ? "" : """" A_AhkPath """" ) A_Space ( """" A_ScriptFullpath """" )
CmdLine := Trim(CmdLine, A_Space)
TaskName := "[RunAsTask] " A_ScriptName " @" SubStr( "000000000" DllCall( "NTDLL\RtlComputeCrc32"
, "Int",0, "WStr",CmdLine, "UInt",StrLen( CmdLine ) * 2, "UInt" ), -9 )
Re: RunAsTask() - Auto-elevates script without UAC prompt
stiuna wrote: ↑22 Jul 2023, 08:24Your script has an error, in these lines:Code: Select all
CmdLine := ( A_IsCompiled ? "" : """" A_AhkPath """" ) A_Space ( """" A_ScriptFullpath """" )
Good catch. . Thanks!
Modified it to:
Code: Select all
CmdLine := ( A_IsCompiled ? "" : """" A_AhkPath " """ ) . ( """" A_ScriptFullpath """" )
Edit: V2 version is here RunAsTask() (25-Jul-2023)
Re: RunAsTask() - Auto-elevates script without UAC prompt
@SKAN That's better, I thought spaces are necessary to separate arguments, I did a quick test and your line works fine.
Re: RunAsTask() - Auto-elevates script without UAC prompt
Greetings!
Here is how I would like to use this script. Is it possible and how would I have to modify it? Too daft to figure it out myself just now.
Run the first instance elevated through Windows task scheduler every time the PC starts, but have it do nothing except wait to be called with a simple numeric command line argument.
When it is run as e. g., it should run a certain command with admin privileges (I know how to check command line args and call the stuff I want). In my case, I want it to shutdown my PC. Currently, I can't get Autohotkey's Shutdown command to work unless the command is issued with admin privileges.
I tried making the script persist to wait for further calls with command line arguments but then on the second call with the argument, I got an error message that the first instance could not be closed, would I want to continue waiting?
Is this even a good idea or is there a simpler way to reliably shutdown a PC from AHK when the main script isn't run with admin privilegs without having to click through a UAC prompt every time?
Many thanks!
Here is how I would like to use this script. Is it possible and how would I have to modify it? Too daft to figure it out myself just now.
Run the first instance elevated through Windows task scheduler every time the PC starts, but have it do nothing except wait to be called with a simple numeric command line argument.
When it is run as e. g.
Code: Select all
RunAsTask.ahk 1
I tried making the script persist to wait for further calls with command line arguments but then on the second call with the argument, I got an error message that the first instance could not be closed, would I want to continue waiting?
Is this even a good idea or is there a simpler way to reliably shutdown a PC from AHK when the main script isn't run with admin privilegs without having to click through a UAC prompt every time?
Many thanks!
Re: RunAsTask() - Auto-elevates script without UAC prompt
I don't understand! why?
This version (for AHK 1.1) of RunAsTask() doesn't process command line parameters.
Code: Select all
#NoTrayIcon
RunAsTask() ; self elevate
Shutdown 5
Re: RunAsTask() - Auto-elevates script without UAC prompt
Thanks for your reply, SKAN!
But that will bring up the UAC dialog, won't it? That's what I'm trying to avoid.
Maybe I'm having a major brain meltdown and am missing the purpose of RunAsTask(). I thought that once I've run it as admin from a task scheduler startup event, I could use it to execute some commands (shutdown, mostly) with admin privilege by calling the script with a certain command line parameter. That's how I understood the introduction to the OP:
Me neither but if I create a script Shutdown.ahk with the only command Shutdown, 1 and execute it from Total Commander (running non-privileged), nothing happens. When I right-click on the script and run it as administrator, I get a UAC prompt and the PC shuts down on confirmation. Hence, I'm looking for a way just to run any kind of shutdown command with admin privileges without having to go through the UAC prompt.
I know, I want to add that part to the script that contains RunAsTask(). So run it once as admin from a task scheduler startup event without parameters to evade UAC, then eventually call it from another script with 1 as command line parameter to have it shutdown the PC rather than go through the RunAsTask() function.This version (for AHK 1.1) of RunAsTask() doesn't process command line parameters.
Code: Select all
#NoTrayIcon
RunAsTask() ; self elevate
Shutdown 5
Maybe I'm having a major brain meltdown and am missing the purpose of RunAsTask(). I thought that once I've run it as admin from a task scheduler startup event, I could use it to execute some commands (shutdown, mostly) with admin privilege by calling the script with a certain command line parameter. That's how I understood the introduction to the OP:
RunAsTask() elevates the calling script by registering a scheduled task with highest privileges on the *first run of the script.
For subsequent runs, it will start a parallel elevated instance via Task scheduler and original instance will exit.
*UAC will prompt on the first run.
Re: RunAsTask() - Auto-elevates script without UAC prompt
Philister wrote: ↑18 Sep 2023, 09:44if I create a script Shutdown.ahk with the only command Shutdown, 1 and execute it from Total Commander (running non-privileged), nothing happens. When I right-click on the script and run it as administrator, I get a UAC prompt and the PC shuts down on confirmation.
What happens when you click launch Shutdown.ahk without admin privileges
Philister wrote: ↑18 Sep 2023, 09:44But that will bring up the UAC dialog, won't it? That's what I'm trying to avoid.Code: Select all
#NoTrayIcon RunAsTask() ; self elevate Shutdown 5
Maybe I'm having a major brain meltdown and am missing the purpose of RunAsTask().
UAC dialog will occur only on the first run.
Re: RunAsTask() - Auto-elevates script without UAC prompt
Literally nothing. The script runs but the shutdown command has no effect. I've tried other command line-based methods of shutting down the PC, e. g. nircmd, but none have any effect on my PC unless run with admin privilege.
I know, but since I run shutdown once every session, I'd rather it'd work without a UAC prompt. Also, I thought if I first ran the script containing RunAsTask() with admin privilege via a task scheduler event on startup, I wouldn't need the prompt on subsequent calls?UAC dialog will occur only on the first run.
Re: RunAsTask() - Auto-elevates script without UAC prompt
Isn't it the default to have to run shutdown.exe (plus, I assume, other shutdown commands like a shutdown.ahk) from an elevated command prompt? This article suggests elevating by default. Thanks!
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: mprost and 129 guests