How Win10 automatically adds administrator rights to batch files

  
Many batch files require administrator privileges at runtime. However, these programs often require the user to manually run as an administrator to function properly. This semi-automatic setting is actually quite cumbersome. Directly with administrator privileges, isn't it more secure?
Copy the following code (between split lines) into Notepad and save it in .bat format (file name can be customized):

————————— Split Line —————————
:::::::: ::::::::::::::::::::::::::::::::: ::::::::::::::::::::::::
:: Softmedia Rubik's Cube automatically adds batch file admin rights: :
:::::::::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::::::::@echo Off
CLS
ECHO.
ECHO ================================================= Soft Media Rubik's Cube to get batch file admin rights
ECHO ========================================= Init
setlocal Disabl eDelayedExpansion
set "batchPath=%~0"
for %%k in (%0) do set batchName=%%~nk
set "vbsGetPrivileges=%temp%OEgetPriv_%batchName%.vbs" ;
setlocal EnableDelayedExpansion
:checkPrivileges
NET FILE 1>NUL 2>NUL
if "%errorlevel%" == "0" ( goto gotPrivileges ) else ( goto getPrivileges )
:getPrivileges
if "%1"=="ELEV" (echo ELEV & shift /1 & goto gotPrivileges)
ECHO.
ECHO *************** *****************
ECHO requests UAC permission approval ……
ECHO ***************** ***************
ECHO Set UAC = CreateObject^("Shell.Application"^) > "%vbsGetPrivileges%"
ECHO args = " ELEV " >> "%vbsGetPrivileges%"
ECHO For Each strArg in WScript.Arguments >> "%vbsGetPrivileges%"
ECHO args = args ^& strArg ^& " " >> "%vbsGetPrivileges%"
ECHO Next >> "%vbsGetPrivileges%"
ECHO UAC.ShellExecute "!batchPa Th!", args, "", "runas", 1 >> "%vbsGetPrivileges%"
"%SystemRoot%System32WScript.exe" "%vbsGetPrivileges%" %*
exit /B
:gotPrivileges
setlocal & pushd .
cd /d %~dp0
if "%1"=="ELEV" (del "%vbsGetPrivileges%" 1>nul 2>nul & shift /1)
:::::::::::::::::::::::::: ::::::::::::::::::::::::::::: Running batch file code::
::::::::::::::::::::::::::::: :::::::::::::::::::::::::::::
rem The following lines can be modified to meet your needs Bat command (from the above three lines of colons to the following can be deleted)
ECHO Welcome to the soft media Rubik's Cube!
ECHO.
pause
—————— ——— split line —————————
The above code is used to get administrator privileges for your bat content, before your code It can be used. The effect is as follows:

▲ Caption: If your system has UAC enabled, you need to approve it after running (don't be bothered, it is better to turn on UAC, it's safer)

▲ Description: Run the example (there is a small partner suspected CMD ugly, so you can adjust the background transparency in the attribute & rarr; color, then change the favorite wallpaper … … ❤ happy holidays ❤)

This code also supports Win7/Win8.1 system, the effect is as follows (Windows7 as an example):


▲ Picture description: Win7 CMD can not set transparent background
Copy code is still more trouble, you can download directly The above prepared documents: http://pan.baidu.com/s/1eSpzkky

Copyright © Windows knowledge All Rights Reserved