Last active
July 2, 2022 14:47
-
-
Save Aetopia/ecbbc1c5ee318bb6c290945c4796c1f7 to your computer and use it in GitHub Desktop.
Simple UAC Prompt for the Windows Command Line.
This file contains 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
@echo off | |
set __COMPAT_LAYER=RunAsInvoker | |
choice.exe /N /C YN /M "Elevate? (Y/N?) > " | |
if %errorlevel% == 1 ( | |
echo Elevation Granted! | |
start /b %* | |
exit /b 0 | |
) else ( | |
if %errorlevel% == 2 ( | |
echo Elevation Denied! | |
exit /b 1 | |
) | |
) |
This file contains 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
$ENV:__COMPAT_LAYER = 'RunAsInvoker' | |
choice.exe /N /C YN /M "Elevate? (Y/N?) > " | |
switch ($LASTEXITCODE) { | |
1 { Write-Output "Elevation Granted!"; Invoke-Expression "$([string]$args)" } | |
2 { Write-Output "Elevation Denied!" } | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment