Batch administrator privileges

Most of the time CMD command request Administrator privileges to run.

Lets make a batch auto check if have admin privileges

@echo off
goto check_Permissions

:check_Permissions
    echo.
    echo ADMINISTRATOR LEVEL REQUESTED. CHECKING PERMISSIONS ...
    echo.

    net session >nul 2>&1
    if %errorLevel% == 0 (
        echo Success: ADMINISTRATION LEVEL PERMISSION CONFIRMED
 	echo.
        cls
    ) else (
   
       echo ATTENTION THIS COMMAND MUST RUN WITH
       echo ADMINISTRATOR PRIVILEGES
       echo:
        echo TO OPEN THE FILE: RIGHT CLICK RUN AS ADMINISTRATOR
       echo.
       set /p DUMMY= PRESS ENTER TO CLOSE THE PROGRAM
	

@EXIT
      
    )

RAM    pause >nul

cls


@echo off
@echo.**********************************************
@echo.
@echo ***** AUTMATIC BACH ADMINISTRATOR LEVEL ******
@echo.
@echo.**********************************************
@echo:
@echo ******  FINALMARCO.COM  **********************
@echo:
@echo.
@echo:

set /p DUMMY= PAUSE

In the first case, the batch just shows just check the administrator permission level, but you can restart with this privileges  automatically  with the code below:

@echo off
goto check_Permissions

:check_Permissions
    echo.
    echo ADMINISTRATOR LEVEL REQUESTED. CHECKING PERMISSIONS ...
    echo.

    net session >nul 2>&1
    if %errorLevel% == 0 (
        echo Success: ADMINISTRATION LEVEL PERMISSION CONFIRMED
 	echo.
        cls
    ) else (
   
       echo ERROR: ATTENTION THIS COMMAND MUST RUN WITH
       echo ADMINISTRATOR PRIVILEGES
       echo:

set /p DUMMY= PRESS ENTER TO RUN THIS PROGRAM WITH ADMINISTRATOR PRIVILEGES

rem Start batch administrator level
        echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\iamtheking.vbs"
        echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\iamtheking.vbs"
        "%temp%\iamtheking.vbs"
        del "%temp%\iamtheking.vbs"
        exit /B


rem @EXIT
      
    )

RAM    pause >nul

cls


@echo off
@echo.**********************************************
@echo.
@echo ***** AUTMATIC BACH ADMINISTRATOR LEVEL ******
@echo.
@echo.**********************************************
@echo:
@echo ******  FINALMARCO.COM  **********************
@echo:
@echo.
@echo:
set /p DUMMY= PAUSE

Enjoy.

Tested on windows7, windows8, and windows 10.

Are you a lazy bastard? download the bat files below

Questions? Suggestions? Please leave a comment below.
I've really saved your ass? Buy me a beer

Tagged with: , , ,

3 Comments on “Batch administrator privileges

Leave a Reply

Your email address will not be published. Required fields are marked *

*