How to use a Windows Script with admin rights built in


A batch file is a text file containing lines with commands that can be executed sequentially by the MS-DOS or Windows command interpreter. They are identified by the extensions .bat or .cmd.

wikipedia

Place this code right after @echo off

This will ask for admin permission rights after executing the script. Fantastic, don’t you think?

> nul 2>&1 "%SYSTEMROOT%\system32\cacls.exe" "%SYSTEMROOT%\system32\config\system"
if '%errorlevel%' NEQ '0' (
    goto AbrirUAC
) else ( 
    goto AbrirBatch
)
:AbrirUAC
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\privilegio.vbs"
echo UAC.ShellExecute "%~s0", "", "", "runas", 1 >> "%temp%\privilegio.vbs"
"%temp%\privilegio.vbs"
exit /b 0
:AbrirBatch
if exist "%temp%\privilegio.vbs" ( 
    del "%temp%\privilegio.vbs" 
)
pushd "%cd%"
cd /d "%~dp0"
Subscribe
Notify of
guest
0 Comentários
Inline Feedbacks
View all comments