RunAsTask() - Auto-elevates script without UAC prompt

Post your working scripts, libraries and tools for AHK v1.1 and older
Gweek
Posts: 64
Joined: 24 Sep 2015, 06:29

Re: RunAsTask() - Auto-elevates script without UAC prompt

06 Jan 2016, 13:58

to where should i copy paste it
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: RunAsTask() - Auto-elevates script without UAC prompt

06 Jan 2016, 14:26

Make a new script.ahk
Image Image Image Image Image
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]
Gweek
Posts: 64
Joined: 24 Sep 2015, 06:29

Re: RunAsTask() - Auto-elevates script without UAC prompt

06 Jan 2016, 14:43

joedf wrote:Make a new script.ahk
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 all
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: RunAsTask() - Auto-elevates script without UAC prompt

06 Jan 2016, 17:46

What does the entry look like?
Can you export the configuration to a file?
Image Image Image Image Image
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]
Gweek
Posts: 64
Joined: 24 Sep 2015, 06:29

Re: RunAsTask() - Auto-elevates script without UAC prompt

06 Jan 2016, 18:10

here is the exported xml file

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>
and a pic
ScreenShot_20160107043729.png
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: RunAsTask() - Auto-elevates script without UAC prompt

06 Jan 2016, 23:00

it says you are trying to run this? C:\Users\Droyk\Desktop\a.ahk ??
Image Image Image Image Image
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]
Gweek
Posts: 64
Joined: 24 Sep 2015, 06:29

Re: RunAsTask() - Auto-elevates script without UAC prompt

07 Jan 2016, 00:03

joedf wrote:it says you are trying to run this? C:\Users\Droyk\Desktop\a.ahk ??
that only a script name i rename the script to newscript.ahk to a.ahk
only content matter right not the script name
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: RunAsTask() - Auto-elevates script without UAC prompt

07 Jan 2016, 07:30

Correct.
Did you try running the task ?
Image Image Image Image Image
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]
Gweek
Posts: 64
Joined: 24 Sep 2015, 06:29

Re: RunAsTask() - Auto-elevates script without UAC prompt

07 Jan 2016, 11:23

joedf wrote:Correct.
Did you try running the task ?
yup i tried but still nothing happens task scheduler doesn't give any type of error and my program doesn't start at all
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: RunAsTask() - Auto-elevates script without UAC prompt

07 Jan 2016, 12:02

the task runs A.ahk, does A.ahk do anything?
Image Image Image Image Image
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]
Gweek
Posts: 64
Joined: 24 Sep 2015, 06:29

Re: RunAsTask() - Auto-elevates script without UAC prompt

07 Jan 2016, 13:10

joedf wrote:the task runs A.ahk, does A.ahk do anything?
nothing it does nothing at all i don't know why though
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: RunAsTask() - Auto-elevates script without UAC prompt

08 Jan 2016, 10:27

Add this to the bottom of your script
MsgBox, Hello.
Then try running the task?
Image Image Image Image Image
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]
Gweek
Posts: 64
Joined: 24 Sep 2015, 06:29

Re: RunAsTask() - Auto-elevates script without UAC prompt

08 Jan 2016, 12:07

joedf wrote:Add this to the bottom of your script
MsgBox, Hello.
Then try running the task?
hmm seems like script is running but the program isn't running don't why though
if i run the program normal as i normally does it will run fine but if i run this script it will not run dont know why :salute: :!: :?:
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: RunAsTask() - Auto-elevates script without UAC prompt

08 Jan 2016, 16:47

What is the program you are trying to run?
Image Image Image Image Image
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]
Gweek
Posts: 64
Joined: 24 Sep 2015, 06:29

Re: RunAsTask() - Auto-elevates script without UAC prompt

09 Jan 2016, 01:31

joedf wrote:What is the program you are trying to run?
Does not matter because i have tried multiple programs and i think i could be doing something wrong tell me something
does your script run fine on your computer

and

i made a video of what i am doing exactly here is the link https://streamable.com/97zv

See the video till the end and tell me if i am doing something wrong
Gweek
Posts: 64
Joined: 24 Sep 2015, 06:29

Re: RunAsTask() - Auto-elevates script without UAC prompt

14 Jan 2016, 11:22

joedf wrote:What is the program you are trying to run?
So did u find any solutions
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: RunAsTask() - Auto-elevates script without UAC prompt

14 Jan 2016, 12:02

sorry for the lateness, had forgotten about this topic. :P

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%
Image Image Image Image Image
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]
Gweek
Posts: 64
Joined: 24 Sep 2015, 06:29

Re: RunAsTask() - Auto-elevates script without UAC prompt

15 Jan 2016, 01:51

joedf wrote:sorry for the lateness, had forgotten about this topic. :P

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%

thanxxx it's working now but the problem remain the same :( when i run this script it run's the program thanxx for that joedf but if i run the script and close the program and then run the program through the icon it will ask for administrator permission :(
do you remember i said 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
and you commented this :
joedf 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.
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 all
and what's happening is i have to add the .exe name to the script and then run the program through the script that's a really big disadvantage for me ,, :(
User avatar
joedf
Posts: 8937
Joined: 29 Sep 2013, 17:08
Location: Canada
Contact:

Re: RunAsTask() - Auto-elevates script without UAC prompt

15 Jan 2016, 10:08

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/
Image Image Image Image Image
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]
Gweek
Posts: 64
Joined: 24 Sep 2015, 06:29

Re: RunAsTask() - Auto-elevates script without UAC prompt

21 Jan 2016, 09:45

joedf 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/
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 it
Hey 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 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 it
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.
so what i want is to run the script and skips every uac prompts every .that's what i wanted :(

Return to “Scripts and Functions (v1)”

Who is online

Users browsing this forum: No registered users and 77 guests