@echo off
:: BatchGotAdmin
:-------------------------------------REM --> Check for permissions>nul 2>&1 "%SYSTEMROOT%\system32\cacls.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 echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\getadmin.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\getadmin.vbs"
"%temp%\getadmin.vbs"
exit /B
:gotAdmin if exist "%temp%\getadmin.vbs" ( del "%temp%\getadmin.vbs" )
pushd "%CD%"
CD /D "%~dp0":--------------------------------------
<YOUR BATCH SCRIPT HERE>
Basically this just creates a VBS Script on the fly and invokes the batch script using it. It checks to see if the current window is running as administrator by attempting to create a folder that requires administrative access. If the directory can not be created, then it invokes the UAC dialog, then closes the non-admin window. The script can also be executed from an already open administrative CLI.
https://sites.google.com/site/eneerge/home/BatchGotAdmin本文链接:https://kinber.cn/post/1732.html 转载需授权!
推荐本站淘宝优惠价购买喜欢的宝贝:

支付宝微信扫一扫,打赏作者吧~
