Run A Program As Admini But Without The UAC Prompt

Get help with using AutoHotkey and its commands and hotkeys
yabab33299
Posts: 98
Joined: 06 May 2020, 17:16

Run A Program As Admini But Without The UAC Prompt

25 Jul 2020, 15:42

Hi, how do I run a program as admin but without the prompt popping up and no need for pressing the YES button?
BoBo
Posts: 4354
Joined: 13 May 2014, 17:15

Re: Run A Program As Admini But Without The UAC Prompt

25 Jul 2020, 16:14

You mean the most suspicious option ever?! :wtf:
yabab33299
Posts: 98
Joined: 06 May 2020, 17:16

Re: Run A Program As Admini But Without The UAC Prompt

25 Jul 2020, 17:01

BoBo wrote:
25 Jul 2020, 16:14
You mean the most suspicious option ever?! :wtf:
I have no idea what you mean
RickC
Posts: 253
Joined: 27 Oct 2013, 08:32

Re: Run A Program As Admini But Without The UAC Prompt

25 Jul 2020, 22:36

yabab33299 wrote:
25 Jul 2020, 17:01
BoBo wrote:
25 Jul 2020, 16:14
You mean the most suspicious option ever?! :wtf:
I have no idea what you mean
I suspect BoBo means "What is the point of Windows having built-in security if AutoHotkey can be used easily to circumvent that security?" :facepalm:

The security is there for a purpose. Try working with it rather than attempting to work around it.

There IS a way to do it using a scheduled task but it's not easy and needs elevated rights to create... for a very good reason, otherwise every script kiddie in the world would be blatting Windows installs for fun.
User avatar
flyingDman
Posts: 883
Joined: 29 Sep 2013, 19:01

Re: Run A Program As Admini But Without The UAC Prompt

25 Jul 2020, 23:11

RunAsTask() as been around for 6 years. I use use to run a PowerShell script to update Chocolatey installed apps. I know the risks and I do not need to be reminded every time I run the script!. I don't believe there is an issue here.
RunAsTask() can be found here: https://www.autohotkey.com/boards/viewtopic.php?t=4334.
yabab33299
Posts: 98
Joined: 06 May 2020, 17:16

Re: Run A Program As Admini But Without The UAC Prompt

26 Jul 2020, 11:18

flyingDman wrote:
25 Jul 2020, 23:11
RunAsTask() as been around for 6 years. I use use to run a PowerShell script to update Chocolatey installed apps. I know the risks and I do not need to be reminded every time I run the script!. I don't believe there is an issue here.
RunAsTask() can be found here: https://www.autohotkey.com/boards/viewtopic.php?t=4334.
Is this safe to use? the RunAsTask()
RickC
Posts: 253
Joined: 27 Oct 2013, 08:32

Re: Run A Program As Admini But Without The UAC Prompt

26 Jul 2020, 11:23

yabab33299 wrote:
26 Jul 2020, 11:18
flyingDman wrote:
25 Jul 2020, 23:11
RunAsTask() as been around for 6 years. I use use to run a PowerShell script to update Chocolatey installed apps. I know the risks and I do not need to be reminded every time I run the script!. I don't believe there is an issue here.
RunAsTask() can be found here: https://www.autohotkey.com/boards/viewtopic.php?t=4334.
Is this safe to use? the RunAsTask()
It's safe to use. It's just a method to automate creation of the required scheduled task. Note that you WILL see a UAC prompt the first time it is used... but not for subsequent uses.
User avatar
flyingDman
Posts: 883
Joined: 29 Sep 2013, 19:01

Re: Run A Program As Admini But Without The UAC Prompt

26 Jul 2020, 11:40

yabab33299 wrote:
26 Jul 2020, 11:18
Is this safe to use? the RunAsTask()
It is just as safe (or as risky!) as pressing YES in the UAC box...
yabab33299
Posts: 98
Joined: 06 May 2020, 17:16

Re: Run A Program As Admini But Without The UAC Prompt

26 Jul 2020, 19:03

RickC wrote:
26 Jul 2020, 11:23
yabab33299 wrote:
26 Jul 2020, 11:18
flyingDman wrote:
25 Jul 2020, 23:11
RunAsTask() as been around for 6 years. I use use to run a PowerShell script to update Chocolatey installed apps. I know the risks and I do not need to be reminded every time I run the script!. I don't believe there is an issue here.
RunAsTask() can be found here: https://www.autohotkey.com/boards/viewtopic.php?t=4334.
Is this safe to use? the RunAsTask()
It's safe to use. It's just a method to automate creation of the required scheduled task. Note that you WILL see a UAC prompt the first time it is used... but not for subsequent uses.
It is so complex, I don't know how to use it. Does anyone have a sample ?
User avatar
flyingDman
Posts: 883
Joined: 29 Sep 2013, 19:01

Re: Run A Program As Admini But Without The UAC Prompt

26 Jul 2020, 19:21

Actually it is pretty easy to use. Run the function at the top of your script. As I said I use it with Chocolatey and this is the script (including the function which can be put in a Lib:

Code: Select all

RunAsTask() 

psScript := "choco upgrade all -y | clip"	
RunWait PowerShell.exe %psScript%,, hide 

;------ function --------------------------------------------------------------------------------------


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
} ; _____________________________________________________________________________________________________

Return to “Ask For Help”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot], hasantr, swrong, Xeo786 and 41 guests