this script only simplifies the work to do, in order to create a "UAC-skipping" shortcut.
If you want everything without UAC, then you might as well disable it.
Sorry
RunAsTask() - Auto-elevates script without UAC prompt
Re: RunAsTask() - Auto-elevates script without UAC prompt
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: RunAsTask() - Auto-elevates script without UAC prompt
actually that's the problem for some metro apps i am working on and developing on.if i disable the uac they will disable too.joedf wrote:this script only simplifies the work to do, in order to create a "UAC-skipping" shortcut.
If you want everything without UAC, then you might as well disable it.
Sorry
Re: RunAsTask() - Auto-elevates script without UAC prompt
Oh metroapps? nooooo nooo.... that's not going to work... They launch by app-references not by file path...
Windows 10 x64 Professional, Intel i5-8500, NVIDIA GTX 1060 6GB, 2x16GB Kingston FURY Beast - DDR4 3200 MHz | [About Me] | [About the AHK Foundation] | [Courses on AutoHotkey]
[ASPDM - StdLib Distribution] | [Qonsole - Quake-like console emulator] | [LibCon - Autohotkey Console Library]
Re: RunAsTask() - Auto-elevates script without UAC prompt
you didn't understand i am not bypassing uac for metroapps i am bypassing uac for some other networking work.........but sadly uac just a nuisance right now ...it makes my work tooo hardjoedf wrote:Oh metroapps? nooooo nooo.... that's not going to work... They launch by app-references not by file path...
Re: RunAsTask() - Auto-elevates script without UAC prompt
I have been looking into why RunAsTask was not working for me in some instances with compiled scripts.
The problem seems to be with this line:
Run *RunAs %CmdLine%, %A_ScriptDir%, UseErrorLevel
If CmdLine contains "D:\Some Path\Some Script.exe" (The string contains quotes) then AHK tries to exectue Run, *RunAs "D:\Some Path\Some Script.exe" which fails with a "File not found" error. Instead the command-line should be Run, *RunAs D:\Some Path\Some Script.exe
Here is my temporary fix:
Also, what's the deal with the statement "It is up to the user to clean and maintain the task scheduler."? I looked in the task scheduler and there were a couple of entries which appeared to be old and no longer needed - is this list potentially going to bloat and bloat over time?
Is it technically feasible to programatically maintain this list? ie for a given filename, ensure there is only ever one entry in the scheduler?
It looks like you should be able to call GetTasks which will give you an IRegisteredTaskCollection.
Any ideas on how to enumerate that?
I guess you could search for any tasks that match the pattern [RunAsTask] <ScriptName> but have a different number after the @ (ie have a different path).
It would mean that you could only have one script with the same as a registered task, but that does not seem too burdensome to me.
The problem seems to be with this line:
Run *RunAs %CmdLine%, %A_ScriptDir%, UseErrorLevel
If CmdLine contains "D:\Some Path\Some Script.exe" (The string contains quotes) then AHK tries to exectue Run, *RunAs "D:\Some Path\Some Script.exe" which fails with a "File not found" error. Instead the command-line should be Run, *RunAs D:\Some Path\Some Script.exe
Here is my temporary fix:
Code: Select all
If ( not A_IsAdmin and not TaskExists ) {
CLine := ( A_IsCompiled ? A_ScriptFullpath : """" A_AhkPath """ """ A_ScriptFullpath """" )
Run *RunAs %CLine%, %A_ScriptDir%, UseErrorLevel
OutputDebug % "AHK| RunAsAdmin ErrorLevel is: " ErrorLevel ", A_LastError is: " A_LastError
if (ErrorLevel != "ERROR")
ExitApp
}
Is it technically feasible to programatically maintain this list? ie for a given filename, ensure there is only ever one entry in the scheduler?
It looks like you should be able to call GetTasks which will give you an IRegisteredTaskCollection.
Any ideas on how to enumerate that?
I guess you could search for any tasks that match the pattern [RunAsTask] <ScriptName> but have a different number after the @ (ie have a different path).
It would mean that you could only have one script with the same as a registered task, but that does not seem too burdensome to me.
Re: RunAsTask() - Auto-elevates script without UAC prompt
evilC wrote: It looks like you should be able to call GetTasks which will give you an IRegisteredTaskCollection.
Any ideas on how to enumerate that?
I guess you could search for any tasks that match the pattern [RunAsTask] <ScriptName> but have a different number after the @ (ie have a different path).
It would mean that you could only have one script with the same as a registered task, but that does not seem too burdensome to me.
Code: Select all
;Thanks to HotKeyIt and Lexikos: https://autohotkey.com/boards/viewtopic.php?t=15316
if (!A_IsAdmin) {
Run *RunAs "%A_AhkPath%" "%A_ScriptFullPath%",, UseErrorLevel
ExitApp
}
TaskSchd := ComObjCreate( "Schedule.Service" ), TaskSchd.Connect()
, TaskRoot := TaskSchd.GetFolder( "\" )
for task in TaskRoot.GetTasks(0) {
;MsgBox % task.Name
if (task.Name == "Vrai reconnait vrai")
TaskRoot.DeleteTask(task.Name, 0)
}
(Also, in the task XML, I'd add <Priority>4</Priority> after ExecutionTimeLimit>PT0S</ExecutionTimeLimit>. Or just as when you add a task manually to the Task Scheduler, your script will be running with Below Normal CPU priority and Low I/O priority...)
Re: RunAsTask() - Auto-elevates script without UAC prompt
This is driving me crazy. I'm trying to use this function to allow non-admin users to run WMIC in a console as an administrator. It works great for me-- I get the UAC prompt (just yes/no-- not a credentials prompt since I'm a domain admin) then on subsequent runs I am no longer prompted. For a standard user, when UAC prompts for username/password, I enter my credentials, and the script runs properly. On subsequent runs, the user still gets a UAC prompt for an admin username/password each time they run it. If I go look at the scheduled tasks for that user, there is no new entries. If I flip over to my profile on the same PC, there exists the scheduled task from the aforementioned first run. Am I confused about the purpose of this script?
Re: RunAsTask() - Auto-elevates script without UAC prompt
I don't think that the intended use is to allow the script to run as a different user, it's intention is to elevate the logged-on user.
Re: RunAsTask() - Auto-elevates script without UAC prompt
Thanks. I apologize for my inarticulateness-- I do want to elevate the logged-on user.evilC wrote:I don't think that the intended use is to allow the script to run as a different user, it's intention is to elevate the logged-on user.
Standard, logged-on user doesn't have the privilege to run the command I'm wanting them to be able to run.
Re: RunAsTask() - Auto-elevates script without UAC prompt
https://en.wikipedia.org/wiki/User_Account_Control
Sounds more like you are trying to run as another account - I *think* (but I could be wrong) that RunAsTask is only able to allow the process to inherit the admin privileges of the logged-on usera user account may have administrator privileges assigned to it, but applications that the user runs do not inherit those privileges unless they are approved beforehand or the user explicitly authorizes it
Re: RunAsTask() - Auto-elevates script without UAC prompt
gotcha. So, literally just makes it so you only have to say "yes" once. Thanks again.evilC wrote:https://en.wikipedia.org/wiki/User_Account_ControlSounds more like you are trying to run as another account - I *think* (but I could be wrong) that RunAsTask is only able to allow the process to inherit the admin privileges of the logged-on usera user account may have administrator privileges assigned to it, but applications that the user runs do not inherit those privileges unless they are approved beforehand or the user explicitly authorizes it
-
- Posts: 935
- Joined: 30 Sep 2017, 03:59
- Location: Romania
- Contact:
Re: RunAsTask() - Auto-elevates script without UAC prompt
Any update on this "temporary fix" ? I am interested in implementing this solution for my compiled script as well.evilC wrote:I have been looking into why RunAsTask was not working for me in some instances with compiled scripts.
The problem seems to be with this line:
Run *RunAs %CmdLine%, %A_ScriptDir%, UseErrorLevel
If CmdLine contains "D:\Some Path\Some Script.exe" (The string contains quotes) then AHK tries to exectue Run, *RunAs "D:\Some Path\Some Script.exe" which fails with a "File not found" error. Instead the command-line should be Run, *RunAs D:\Some Path\Some Script.exe
Here is my temporary fix:Also, what's the deal with the statement "It is up to the user to clean and maintain the task scheduler."? I looked in the task scheduler and there were a couple of entries which appeared to be old and no longer needed - is this list potentially going to bloat and bloat over time?Code: Select all
If ( not A_IsAdmin and not TaskExists ) { CLine := ( A_IsCompiled ? A_ScriptFullpath : """" A_AhkPath """ """ A_ScriptFullpath """" ) Run *RunAs %CLine%, %A_ScriptDir%, UseErrorLevel OutputDebug % "AHK| RunAsAdmin ErrorLevel is: " ErrorLevel ", A_LastError is: " A_LastError if (ErrorLevel != "ERROR") ExitApp }
Is it technically feasible to programatically maintain this list? ie for a given filename, ensure there is only ever one entry in the scheduler?
It looks like you should be able to call GetTasks which will give you an IRegisteredTaskCollection.
Any ideas on how to enumerate that?
I guess you could search for any tasks that match the pattern [RunAsTask] <ScriptName> but have a different number after the @ (ie have a different path).
It would mean that you could only have one script with the same as a registered task, but that does not seem too burdensome to me.
Best regards, Marius.
-------------------------
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
KeyPress OSD v4: GitHub or forum. (presentation video)
Quick Picto Viewer: GitHub or forum.
AHK GDI+ expanded / compilation library (on GitHub)
My home page.
Re: RunAsTask() - Auto-elevates script without UAC prompt
Hi,
Windows 10 x64 v1809
AHK 1.1.32.0 x64
I tried a simple hotkey script:
The first run after UAC confirmation works fine, the scheduler task is created, but any subsequent run does not work, the script exits immediately and the hotkey is not registered. Is this supposed to not work?
Thanks.
Windows 10 x64 v1809
AHK 1.1.32.0 x64
I tried a simple hotkey script:
Code: Select all
RunAsTask()
F9::MsgBox
Thanks.
Re: RunAsTask() - Auto-elevates script without UAC prompt
Works fine In WIn 7 and Win 10.
How are you launching the script for the consecutive calls?
You shouldn't launch it from editor. The command line might change.
PS:
I have been using this with AHK v 1.1.15.03 for past several years without a flaw.
I'll go through the topic and give this function an update.
Re: RunAsTask() - Auto-elevates script without UAC prompt
Simply clicking on test.ahk in Explorer. The "H" icon appears in the tray for a split-second and disappears again. #Persistent does not help. RunAsTask() is defined in %A_MyDocuments%\AutoHotkey\Lib\RunAsTask.ahk.
Thank you.
EDIT: I thought it was related to the hotkey for some reason, but neither does
Code: Select all
RunAsTask()
Run, regedit.exe
Re: RunAsTask() - Auto-elevates script without UAC prompt
Ok! Does the full path to test.ahk have any space(s) in in it?
If yes, move test.ahk to root folder or any folder path that doesn't have spaces and try again.
I went through this topic and this flaw has been reported. I will fix it.
Re: RunAsTask() - Auto-elevates script without UAC prompt
Nope, it does not. c:\test\test.ahk and the behavior is the same. First run works, consecutive runs show the icon for a split-second, then terminate.
Code: Select all
RunAsTask()
MsgBox
Re: RunAsTask() - Auto-elevates script without UAC prompt
Can you check the Task scheduler and confirm if the task was created?TheHacker wrote: ↑23 Apr 2020, 17:29First run works, consecutive runs show the icon for a split-second, then terminate.Code: Select all
RunAsTask() MsgBox
If you right click on the task, you will see an option to export xml.
It will be very helpful if you can post the xml.
Thanks.
Re: RunAsTask() - Auto-elevates script without UAC prompt
Sure, here you are:
Code: Select all
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.6" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<URI>\[RunAsTask] test.ahk @2836152222</URI>
</RegistrationInfo>
<Triggers />
<Principals>
<Principal id="Author">
<UserId>*edited out by SKAN*</UserId>
<LogonType>InteractiveToken</LogonType>
<RunLevel>HighestAvailable</RunLevel>
</Principal>
</Principals>
<Settings>
<MultipleInstancesPolicy>Parallel</MultipleInstancesPolicy>
<DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
<StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
<AllowHardTerminate>false</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable>
<RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
<IdleSettings>
<StopOnIdleEnd>true</StopOnIdleEnd>
<RestartOnIdle>false</RestartOnIdle>
</IdleSettings>
<AllowStartOnDemand>true</AllowStartOnDemand>
<Enabled>true</Enabled>
<Hidden>false</Hidden>
<RunOnlyIfIdle>false</RunOnlyIfIdle>
<DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteAppSession>
<UseUnifiedSchedulingEngine>true</UseUnifiedSchedulingEngine>
<WakeToRun>false</WakeToRun>
<ExecutionTimeLimit>PT0S</ExecutionTimeLimit>
<Priority>7</Priority>
</Settings>
<Actions Context="Author">
<Exec>
<Command>C:\Program Files\AutoHotkey\AutoHotkey.exe</Command>
<Arguments>"C:\test\test.ahk"</Arguments>
<WorkingDirectory>C:\test</WorkingDirectory>
</Exec>
</Actions>
</Task>
Re: RunAsTask() - Auto-elevates script without UAC prompt
My A_AhkPath is D:\AutoHotkey\AutoHotkey.exeTheHacker wrote: ↑24 Apr 2020, 12:14Sure, here you are:Code: Select all
<Command>C:\Program Files\AutoHotkey\AutoHotkey.exe</Command> <Arguments>"C:\test\test.ahk"</Arguments> <WorkingDirectory>C:\test</WorkingDirectory>
Yours should be "C:\Program Files\AutoHotkey\AutoHotkey.exe", that is within double-quotes as there is a space in path.
A silly but costly mistake of mine
Code fixed.
Many thanks for your wonderful cooperation.
Return to “Scripts and Functions (v1)”
Who is online
Users browsing this forum: No registered users and 181 guests