批处理借助JScript/VBScript提升管理员权限
JScript:
@echo off
goto :runas
:main
echo.
echo 当前正在以管理员身份运行...
echo.
pause
exit
:runas
openfiles 1>nul 2>&1 && goto :main
title 以管理员身份运行
set self=%~0
set script=%random%.js
echo new ActiveXObject^("Shell.Application"^).ShellExecute^("%self:\=\\%", null, null, "runas", 1^); >%temp%\%script%
cscript.exe //Nologo %temp%\%script%
del /a /f %temp%\%script%
exit
VBScript:
@echo off
goto :runas
:main
echo.
echo 当前正在以管理员身份运行...
echo.
pause
exit
:runas
openfiles 1>nul 2>&1 && goto :main
title 以管理员身份运行
mshta VBScript:Execute("CreateObject(""Shell.Application"").ShellExecute ""%~0"", Null, Null, ""runas"", 1: Close")
exit

浙公网安备 33010602011771号