Re: RunAsTask() - Auto-elevates script without UAC prompt
Posted: 06 Jan 2016, 13:58
to where should i copy paste it
Let's help each other out
https://www.autohotkey.com/boards/
did it and run it and now it's the same thing it make's an entry on task scheduler and then my program doesnt run at alljoedf wrote:Make a new script.ahk
Code: Select all
<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.5" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
<RegistrationInfo>
<URI>\[RunAsTask] a.ahk @3549296603</URI>
</RegistrationInfo>
<Triggers />
<Principals>
<Principal id="Author">
<UserId>S-1-5-21-3817510688-677580754-3005797570-1001</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:\Users\Droyk\Desktop\a.ahk"</Arguments>
<WorkingDirectory>C:\Users\Droyk\Desktop</WorkingDirectory>
</Exec>
</Actions>
</Task>
that only a script name i rename the script to newscript.ahk to a.ahkjoedf wrote:it says you are trying to run this? C:\Users\Droyk\Desktop\a.ahk ??
yup i tried but still nothing happens task scheduler doesn't give any type of error and my program doesn't start at alljoedf wrote:Correct.
Did you try running the task ?
nothing it does nothing at all i don't know why thoughjoedf wrote:the task runs A.ahk, does A.ahk do anything?
hmm seems like script is running but the program isn't running don't why thoughjoedf wrote:Add this to the bottom of your script
MsgBox, Hello.
Then try running the task?
Does not matter because i have tried multiple programs and i think i could be doing something wrong tell me somethingjoedf wrote:What is the program you are trying to run?
So did u find any solutionsjoedf wrote:What is the program you are trying to run?
Code: Select all
#NoTrayIcon
MyProgram := "C:\path\to\the\program.exe"
RunAsTask() { ; By SKAN, http://goo.gl/yG6A1F, CD:19/Aug/2014 | MD:22/Aug/2014
Local CmdLine, TaskName, TaskExists, XML, TaskSchd, TaskRoot, RunAsTask
Local TASK_CREATE := 0x2, TASK_LOGON_INTERACTIVE_TOKEN := 3
Try TaskSchd := ComObjCreate( "Schedule.Service" ), TaskSchd.Connect()
, TaskRoot := TaskSchd.GetFolder( "\" )
Catch
Return "", ErrorLevel := 1
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 )
Try RunAsTask := TaskRoot.GetTask( TaskName )
TaskExists := ! A_LastError
If ( not A_IsAdmin and TaskExists ) {
RunAsTask.Run( "" )
ExitApp
}
If ( not A_IsAdmin and not TaskExists ) {
Run *RunAs %CmdLine%, %A_ScriptDir%, UseErrorLevel
ExitApp
}
If ( A_IsAdmin and not TaskExists ) {
XML := "
( LTrim Join
<?xml version=""1.0"" ?><Task xmlns=""http://schemas.microsoft.com/windows/2004/02/mit/task""><Regi
strationInfo /><Triggers /><Principals><Principal id=""Author""><LogonType>InteractiveToken</LogonT
ype><RunLevel>HighestAvailable</RunLevel></Principal></Principals><Settings><MultipleInstancesPolic
y>Parallel</MultipleInstancesPolicy><DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries><
StopIfGoingOnBatteries>false</StopIfGoingOnBatteries><AllowHardTerminate>false</AllowHardTerminate>
<StartWhenAvailable>false</StartWhenAvailable><RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAva
ilable><IdleSettings><StopOnIdleEnd>true</StopOnIdleEnd><RestartOnIdle>false</RestartOnIdle></IdleS
ettings><AllowStartOnDemand>true</AllowStartOnDemand><Enabled>true</Enabled><Hidden>false</Hidden><
RunOnlyIfIdle>false</RunOnlyIfIdle><DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteApp
Session><UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine><WakeToRun>false</WakeToRun><
ExecutionTimeLimit>PT0S</ExecutionTimeLimit></Settings><Actions Context=""Author""><Exec>
<Command>" ( A_IsCompiled ? A_ScriptFullpath : A_AhkPath ) "</Command>
<Arguments>" ( !A_IsCompiled ? """" A_ScriptFullpath """" : "" ) "</Arguments>
<WorkingDirectory>" A_ScriptDir "</WorkingDirectory></Exec></Actions></Task>
)"
TaskRoot.RegisterTask( TaskName, XML, TASK_CREATE, "", "", TASK_LOGON_INTERACTIVE_TOKEN )
}
Return TaskName, ErrorLevel := 0
} ; _____________________________________________________________________________________________________
RunAsTask()
Run %MyProgram%
joedf wrote:sorry for the lateness, had forgotten about this topic.
Ok, i see the problem, use this script and change the path MyProgram := "C:\path\to\the\program.exe"Code: Select all
#NoTrayIcon MyProgram := "C:\path\to\the\program.exe" RunAsTask() { ; By SKAN, http://goo.gl/yG6A1F, CD:19/Aug/2014 | MD:22/Aug/2014 Local CmdLine, TaskName, TaskExists, XML, TaskSchd, TaskRoot, RunAsTask Local TASK_CREATE := 0x2, TASK_LOGON_INTERACTIVE_TOKEN := 3 Try TaskSchd := ComObjCreate( "Schedule.Service" ), TaskSchd.Connect() , TaskRoot := TaskSchd.GetFolder( "\" ) Catch Return "", ErrorLevel := 1 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 ) Try RunAsTask := TaskRoot.GetTask( TaskName ) TaskExists := ! A_LastError If ( not A_IsAdmin and TaskExists ) { RunAsTask.Run( "" ) ExitApp } If ( not A_IsAdmin and not TaskExists ) { Run *RunAs %CmdLine%, %A_ScriptDir%, UseErrorLevel ExitApp } If ( A_IsAdmin and not TaskExists ) { XML := " ( LTrim Join <?xml version=""1.0"" ?><Task xmlns=""http://schemas.microsoft.com/windows/2004/02/mit/task""><Regi strationInfo /><Triggers /><Principals><Principal id=""Author""><LogonType>InteractiveToken</LogonT ype><RunLevel>HighestAvailable</RunLevel></Principal></Principals><Settings><MultipleInstancesPolic y>Parallel</MultipleInstancesPolicy><DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>< StopIfGoingOnBatteries>false</StopIfGoingOnBatteries><AllowHardTerminate>false</AllowHardTerminate> <StartWhenAvailable>false</StartWhenAvailable><RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAva ilable><IdleSettings><StopOnIdleEnd>true</StopOnIdleEnd><RestartOnIdle>false</RestartOnIdle></IdleS ettings><AllowStartOnDemand>true</AllowStartOnDemand><Enabled>true</Enabled><Hidden>false</Hidden>< RunOnlyIfIdle>false</RunOnlyIfIdle><DisallowStartOnRemoteAppSession>false</DisallowStartOnRemoteApp Session><UseUnifiedSchedulingEngine>false</UseUnifiedSchedulingEngine><WakeToRun>false</WakeToRun>< ExecutionTimeLimit>PT0S</ExecutionTimeLimit></Settings><Actions Context=""Author""><Exec> <Command>" ( A_IsCompiled ? A_ScriptFullpath : A_AhkPath ) "</Command> <Arguments>" ( !A_IsCompiled ? """" A_ScriptFullpath """" : "" ) "</Arguments> <WorkingDirectory>" A_ScriptDir "</WorkingDirectory></Exec></Actions></Task> )" TaskRoot.RegisterTask( TaskName, XML, TASK_CREATE, "", "", TASK_LOGON_INTERACTIVE_TOKEN ) } Return TaskName, ErrorLevel := 0 } ; _____________________________________________________________________________________________________ RunAsTask() Run %MyProgram%
and you commented this :Droyk wrote: I just started using Ahk. and i too don't like UAC prompts .until now i was using task scheduler to skip UAC prompts but now i think i could handle this problem with the help of ahk
so can you plz tell me this script that SKAN created .its only able to skip uac only when i write application name on this script what i want is universal action i want to run this script and boom every application skips uac.
so can you plz tell me how should i modify this script for my use & plz understand i am just foolish noob so plz bear with me
some important facts
i am running windows 10 and don't want to disable uac for some specific reasons
when i run this script every program i click or opens indirectly will skip UAC.
i do a lot of networking work safely without uac on windows 7 but rightnow i have to done some of my works on windows 10 so i want to make this script to easy my burden(UAC are time consuming )
thanxx plz relpy i came here with a lot of hope so plz dont break my hope
so as you can see the problem remain the same what i wanted to do is run the script and and go to the program icon and run the program through the program icon and it will not ask any administrator permission at alljoedf wrote:Well that would be a big security breach... You could have a "central" executable run all your other scripts since the rights will be inherited.
AGAIN i am really Sorry for the really late response i am really sorry about it i am really too busy for someday's so i think you didn't read my first comment properly so plz now read itjoedf wrote:That's not how this works.
If that's what you want, then you don't need AutoHotkey.
Manually create a new task. Follow this tutorial:
http://www.howtogeek.com/howto/windows- ... ows-vista/
so as you can see i was using the task scheduler method until now .but then i thought i can now use ahk for this because i hoped that we can run shortcuts with this and you seem to agree with it but now you are saying the exactly opposite of itHey joedf how are U ? hope you are fine
i just started using Ahk. and i too don't like UAC prompts .until now i was using task scheduler to skip UAC prompts but now i think i could handle this problem with the help of ahk
so what i want is to run the script and skips every uac prompts every .that's what i wantedWell that would be a big security breach... You could have a "central" executable run all your other scripts since the rights will be inherited.