Last active
January 6, 2023 12:59
-
-
Save Clijsters/e8460c8f4614553bba21 to your computer and use it in GitHub Desktop.
Sudo for Windows - Self elevating .bat-File
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@echo off | |
:checkPrivileges | |
NET FILE 1>NUL 2>NUL | |
if '%errorlevel%' == '0' ( | |
goto mainScript | |
) else ( | |
goto getPrivileges | |
) | |
::------------------------------------------------------------------------------------------------- | |
:getPrivileges | |
if '%1'=='ELEV' (shift & goto mainScript) | |
echo. | |
echo Selbstausfuehrung mit Administratorrechten... | |
setlocal DisableDelayedExpansion | |
set "batchPath=%~0" | |
setlocal EnableDelayedExpansion | |
echo Set UAC = CreateObject^("Shell.Application"^) > "%temp%\runAsAdmin.vbs" | |
echo UAC.ShellExecute "!batchPath!", "ELEV", "", "runas", 1 >> "%temp%\runAsAdmin.vbs" | |
"%temp%\runAsAdmin.vbs" | |
exit /B | |
::------------------------------------------------------------------------------------------------- | |
:mainScript | |
REM Here we are doing admin stuff... | |
cls | |
echo Hallo Welt >C:\test.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment