您的位置:首页 > 其它

如何在bat中请求管理员权限

2016-07-14 18:38 232 查看
REM  --> Check for permissions

>nul 2>&1 "%SYSTEMROOT%\system32\icacls.exe" "%SYSTEMROOT%\system32\config\system"

REM --> If error flag set, we do not have admin.

if '%errorlevel%' NEQ '0' (

    echo Requesting administrative privileges...

    goto UACPrompt

) else ( goto gotAdmin )

:UACPrompt
REM output the command  to getadmin.vbs

    echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"

    echo UAC.ShellExecute "%~s0", "%1 %2 %3", "", "runas", 1 >> "%temp%\getadmin.vbs"
REM run getadmin.vbs

    "%temp%\getadmin.vbs"

    exit /B

:gotAdmin
REM delete the temp file

    if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )

    pushd "%CD%"

    CD /D "%~dp0"
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: