Administrator rights to execute bat script

Only you need to add the following script at the beginning of the .bat file you write, and then double-click the .bat file that is based on administrator privileges to perform

@echo off&color 17
if exist "%SystemRoot%\SysWOW64" path %path%;%windir%\SysNative;%SystemRoot%\SysWOW64;%~dp0
bcdedit >nul
if '%errorlevel%' NEQ '0' (goto UACPrompt) else (goto UACAdmin)
:UACPrompt
%1 start "" mshta vbscript:createobject("shell.application").shellexecute("""%~0""","::",,"runas" , 1 ) (window.close) & Exit 
Exit / B 
: UACAdmin 
cd / d " % ~ DP0 " 
echo currently running path is:% CD%
 echo has obtained administrator privileges

 

Guess you like

Origin www.cnblogs.com/yannana/p/11575549.html