Skip to content

Instantly share code, notes, and snippets.

@Aetopia
Last active July 2, 2022 14:47
Show Gist options
  • Save Aetopia/ecbbc1c5ee318bb6c290945c4796c1f7 to your computer and use it in GitHub Desktop.
Save Aetopia/ecbbc1c5ee318bb6c290945c4796c1f7 to your computer and use it in GitHub Desktop.
Simple UAC Prompt for the Windows Command Line.
@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
)
)
$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