Page 3 of 7

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

Posted: 06 Jan 2016, 13:58
by Gweek
to where should i copy paste it

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

Posted: 06 Jan 2016, 14:26
by joedf
Make a new script.ahk

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

Posted: 06 Jan 2016, 14:43
by Gweek
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

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

Posted: 06 Jan 2016, 17:46
by joedf
What does the entry look like?
Can you export the configuration to a file?

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

Posted: 06 Jan 2016, 18:10
by Gweek
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

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

Posted: 06 Jan 2016, 23:00
by joedf
it says you are trying to run this? C:\Users\Droyk\Desktop\a.ahk ??

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

Posted: 07 Jan 2016, 00:03
by Gweek
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

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

Posted: 07 Jan 2016, 07:30
by joedf
Correct.
Did you try running the task ?

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

Posted: 07 Jan 2016, 11:23
by Gweek
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

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

Posted: 07 Jan 2016, 12:02
by joedf
the task runs A.ahk, does A.ahk do anything?

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

Posted: 07 Jan 2016, 13:10
by Gweek
joedf wrote:the task runs A.ahk, does A.ahk do anything?
nothing it does nothing at all i don't know why though

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

Posted: 08 Jan 2016, 10:27
by joedf
Add this to the bottom of your script
MsgBox, Hello.
Then try running the task?

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

Posted: 08 Jan 2016, 12:07
by Gweek
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: :!: :?:

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

Posted: 08 Jan 2016, 16:47
by joedf
What is the program you are trying to run?

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

Posted: 09 Jan 2016, 01:31
by Gweek
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

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

Posted: 14 Jan 2016, 11:22
by Gweek
joedf wrote:What is the program you are trying to run?
So did u find any solutions

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

Posted: 14 Jan 2016, 12:02
by joedf
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%

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

Posted: 15 Jan 2016, 01:51
by Gweek
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 ,, :(

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

Posted: 15 Jan 2016, 10:08
by joedf
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/

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

Posted: 21 Jan 2016, 09:45
by Gweek
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 :(