如何在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"
>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"
相关文章推荐
- httpd-2.2和httpd-2.4虚拟主机的实现
- PAT-乙级-1001. 害死人不偿命的(3n+1)猜想 (15)
- 团体程序设计天梯赛-练习集L2-011. 玩转二叉树
- 团体程序设计天梯赛-练习集L2-010. 排座位
- 团体程序设计天梯赛-练习集L2-009. 抢红包
- 团体程序设计天梯赛-练习集L2-008. 最长对称子串
- 团体程序设计天梯赛-练习集L2-007. 家庭房产
- 团体程序设计天梯赛-练习集L2-006. 树的遍历
- 团体程序设计天梯赛-练习集L2-005. 集合相似度
- 团体程序设计天梯赛-练习集L2-004. 这是二叉搜索树吗
- 剑指offer之面试题23:从上往下打印二叉树
- json
- 启动模式 launchMode小记
- python迭代dict的key和value
- CodeForces Gym 100803A 模拟,贪心
- xUtils简介
- 学习java,考证要素
- TFS安装:base_packet.cpp:246: 错误:从类型‘const char*’到类型‘pthread_t’的转换无效
- Handler机制原理
- ehcache的配置文件