森 • 时光机

CMD、BAT提升管理员权限

在文件的开头,增加以下代码即可:

net session >nul 2>&1
if not "%errorLevel%" == "0" (
  echo Oops: This tools must run with administrator permissions!
  echo it will popup the UAC dialog, please click [Yes] to continue.
  echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
  echo UAC.ShellExecute "%~s0", "%*", "", "runas", 1 >> "%temp%\getadmin.vbs"
  "%temp%\getadmin.vbs"
  exit /b 2
)

当前页面是本站的「Google AMP」版。查看和发表评论请点击:完整版 »