Skip to content

Instantly share code, notes, and snippets.

@lyf-is-coding
Created March 11, 2022 12:04
Show Gist options
  • Save lyf-is-coding/844f9bf2b733f1022f49e2a7765796c7 to your computer and use it in GitHub Desktop.
Save lyf-is-coding/844f9bf2b733f1022f49e2a7765796c7 to your computer and use it in GitHub Desktop.
Windows CMD file get Administrative privileges
@echo off
:: BatchGotAdmin
:-------------------------------------
REM --> Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
REM --> If error flag set, we do not have admin.
IF '%errorlevel%' NEQ '0' (
ECHO Requesting administrative privileges...
GOTO UACPrompt
) ELSE GOTO gotAdmin
:UACPrompt
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
ECHO UAC.ShellExecute "%~s0", "%~s1", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
del /q "%temp%\getadmin.vbs"
EXIT /B 1
:gotAdmin
ECHO Got Admin :D
pause
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment