Last active
December 12, 2015 02:38
-
-
Save ddhahn/4700115 to your computer and use it in GitHub Desktop.
Envoke UAC to elevate a command
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#NoTrayIcon | |
#Region ;**** Directives created by AutoIt3Wrapper_GUI **** | |
#AutoIt3Wrapper_Outfile=elevate_this.exe | |
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI **** | |
;Run a script using shellexecute runas. This will run the application/script | |
;at the highest available privilege level. Depending on UAC settings, this may | |
;cause a UAC prompt. | |
;Examples: | |
;elevate_this.exe c:\windows\system32\cscript.exe script.vbs /q /w /r /s | |
; THis would end up running wscript.exe with the arguments script.vbs /q /w /r /s | |
;+--- construct the new command line arguments so that we can preserve any quotes used in parameters passed to it | |
;+--- if $cmdline[1] begins with a double quote, we need to add three to the length $cmdline[1] to account for the extra | |
;+--- double quote. | |
if stringleft($cmdlineraw,1) = '"' Then | |
$newargs = stringmid($cmdlineraw,stringlen($cmdline[1])+3) | |
Else | |
$newargs = stringmid($cmdlineraw,stringlen($cmdline[1])+2) | |
EndIf | |
;+--- if we have a command line parameter, pass it. If not, don't. | |
if $cmdline[0] = 1 Then | |
exit(ShellExecuteWait('"' & $cmdline[1] & '"',"","","runas")) | |
Else | |
exit(ShellExecuteWait('"' & $cmdline[1] & '"',$newargs,"","runas")) | |
endIf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment