- Downloaded
- 5.7 GB
- Uploaded
- 448.6 GB
- Ratio
- 78.11
- Seedbonus
- 134,973
- Upload Count
- 217 (223)
Member for 5 years
Create an elevated BAT file, run as administrator [Batch]
On some occasions we have needed to create a
There are many ways to achieve this result, I will share one that works well.
They should start writing the code they need to run as administrator below this line:
That's it all.
On some occasions we have needed to create a
.bat
file and have it run with administrator permissions within its own code, without the need to create shortcuts or provide permissions externally.There are many ways to achieve this result, I will share one that works well.
They should start writing the code they need to run as administrator below this line:
REM --> Start writing your code below this line
That's it all.
Bash:
@if (@CodeSection == @Batch) @then
@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"
:--------------------------------------
REM --> Start writing your code below this line
@end