Team OS : Your Only Destination To Custom OS !!

Welcome to TeamOS Community, Register or Login to the Community to Download Torrents, Get Access to Shoutbox, Post Replies, Use Search Engine and many more features. Register Today!

Tips & Tricks Create an elevated BAT file - run as administrator [Batch]

juanamm

Uploader
Uploader
Power User
✅ Verified Member
Member
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 .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
 

fantom

Power User
✅ Verified Member
Member
Downloaded
1.3 TB
Uploaded
1,588.3 TB
Ratio
1188.25
Seedbonus
180,926,776
Upload Count
0 (0)
Member for 10 years
Very usefull juanamm

Thank You for share it with us :clap:
 

pascalwil

✅ Verified Member
Member
Downloaded
1.3 TB
Uploaded
36.2 TB
Ratio
28.55
Seedbonus
21,250
Upload Count
0 (0)
Member for 8 years
Thank you for the tip
 

SlavkoPejic

Power User
✅ Verified Member
Member
Downloaded
200.5 GB
Uploaded
80.1 TB
Ratio
409
Seedbonus
497,579
Upload Count
0 (0)
Member for 5 years
Thank you, Very good share
 

herve44

Member
Downloaded
31.4 GB
Uploaded
261.2 GB
Ratio
8.32
Seedbonus
1,122
Upload Count
0 (0)
Member for 4 years
Thank you for this very interesting tip.
 

RedDove

⭐ VIP
Power User
✅ Verified Member
Member
Downloaded
118.2 GB
Uploaded
41.6 TB
Ratio
360.36
Seedbonus
1,840,546
Upload Count
0 (0)
Member for 9 years
I don't think I'm confident enough to try that,
but maybe one day, who knows.

Thank you for showing us how it's done anyway. :)
 

Vidyaarthi

✅ Verified Member
Member
Downloaded
146.5 GB
Uploaded
3.3 TB
Ratio
23.4
Seedbonus
652,067
Upload Count
0 (0)
Member for 5 years
Thank you.

Shouldn't it be marked "Tutorial"?
 

juanamm

Uploader
Uploader
Power User
✅ Verified Member
Member
Downloaded
5.7 GB
Uploaded
448.6 GB
Ratio
78.11
Seedbonus
134,973
Upload Count
217 (223)
Member for 5 years
Thank you.

Shouldn't it be marked "Tutorial"?
Thank you for your appreciation, I considered it a simple tip, since the tutorials are somewhat more explanatory, with instructions on the steps to follow. :)
 

TOSm0d

Member
Downloaded
49.9 GB
Uploaded
151.7 GB
Ratio
3.04
Seedbonus
1,216
Upload Count
0 (0)
Member for 4 years
good share and very useful, thank you
 
Top