Last active
August 8, 2024 02:59
-
-
Save neuralpain/4bcc08065fe79e4597eb65ed707be90d to your computer and use it in GitHub Desktop.
Invoke UAC prompt for Windows Batch scripts.
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
:: fsutil [...] is a universal method for checking | |
:: administrator privilages. works from Windows XP | |
:: and onwards | |
fsutil dirty query %systemdrive% >nul | |
:: if error, we do not have admin. | |
if %ERRORLEVEL% NEQ 0 ( | |
cls & echo. | |
echo This script requires administrative priviledges. | |
echo Attempting to elevate... | |
goto UAC_Prompt | |
) else goto :begin_script | |
:UAC_Prompt | |
set n=%0 %* | |
set n=%n:"=" ^& Chr(34) ^& "% | |
echo Set objShell = CreateObject("Shell.Application")>"%tmp%\cmdUAC.vbs" | |
echo objShell.ShellExecute "cmd.exe", "/c start " ^& Chr(34) ^& "." ^& Chr(34) ^& " /d " ^& Chr(34) ^& "%CD%" ^& Chr(34) ^& " cmd /c %n%", "", "runas", ^1>>"%tmp%\cmdUAC.vbs" | |
cscript "%tmp%\cmdUAC.vbs" //Nologo | |
del "%tmp%\cmdUAC.vbs" | |
goto :eof | |
:begin_script | |
:: TODO... | |
exit |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Simple guide
begin_script
(line 12) with the label of your script body