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"
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
exit /B
:gotAdmin
REM delete the temp file
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0"
本文介绍了一个用于检查当前用户是否拥有管理员权限的批处理脚本。如果检测到没有足够的权限,则会提示用户并尝试提升权限以继续执行进一步的任务。
714

被折叠的 条评论
为什么被折叠?



