Skip to content

Instantly share code, notes, and snippets.

@devomman
Last active October 30, 2021 12:32
Show Gist options
  • Save devomman/428c8f6c932a36235a5257c3bf8b69b6 to your computer and use it in GitHub Desktop.
Save devomman/428c8f6c932a36235a5257c3bf8b69b6 to your computer and use it in GitHub Desktop.
Using Batch file Run as Administrator Privilege
@echo off
:: (Run as Admin code starts)
REM Check for permissions
>nul 2>&1 "%SYSTEMROOT%\system32\icacls.exe" "%SYSTEMROOT%\system32\config\system"
REM If error flag set, we do not have admin.
if '%errorlevel%' NEQ '0' (
echo Now Running As 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"
:: (Run as Admin code ends)
::=======================================
::=======================================
:: (Your code is start from here:)
::===========================>
@echo off
call "%~dp0Microsoft_Updates\office\Install_Updates.bat"
call "%~dp0Microsoft_Updates\windows\Install_Updates.bat"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment