Created
March 11, 2022 12:04
-
-
Save lyf-is-coding/844f9bf2b733f1022f49e2a7765796c7 to your computer and use it in GitHub Desktop.
Windows CMD file get Administrative privileges
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
@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