If you want everything without UAC, then you might as well disable it.
Sorry
![Sad :(](./images/smilies/icon_e_sad.gif)
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
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...
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
}
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)
}
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.
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
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
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.
Code: Select all
RunAsTask()
F9::MsgBox
Works fine In WIn 7 and Win 10.
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.
Code: Select all
RunAsTask()
Run, regedit.exe
Ok! Does the full path to test.ahk have any space(s) in in it?
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
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
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>
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>